n = STDIN.readline.to_i
x_min, y_min = 10**10, 10**10
x_max, y_max = -x_min, -y_min
n.times do
	x, y = STDIN.readline.split.map {|s| s.to_i }
	x_min = x if x < x_min
	y_min = y if y < y_min
	x_max = x if x > x_max
	y_max = y if y > y_max
end
a, b = x_max-x_min, y_max-y_min
puts [a, b].max**2

n= gets.to_i
mx, my, lx, ly = -1.0/0.0, -1.0/0.0, 1.0/0.0, 1.0/0.0
n.times do
  x,y = gets.split.map(&:to_i)
  mx = [mx,x].max
  my = [my,y].max
  lx = [lx,x].min
  ly = [ly,y].min
end
puts [mx-lx,my-ly].max**2

data = gets.to_i.times.map{gets.split.map{|x|x.to_i}}
min_x = data.map{|x|x[0]}.min
max_x = data.map{|x|x[0]}.max
min_y = data.map{|x|x[1]}.min
max_y = data.map{|x|x[1]}.max
result = [(max_x - min_x), (max_y - min_y)].max**2
puts result

# 485B

min_x = min_y = 10 ** 9 + 1
max_x = max_y = -min_x
gets.to_i.times do
  x, y = gets.chomp.split.map &:to_i
  if x < min_x
    min_x = x
  end
  if x > max_x
    max_x = x
  end
  if y < min_y
    min_y = y
  end
  if y > max_y
    max_y = y
  end
end
puts [max_x - min_x, max_y - min_y].max ** 2

n = gets.to_i
maxX = -10 ** 9
maxY = -10 ** 9
minX = 10 ** 9
minY = 10 ** 9
n.times do
	input = gets
	x_coor = input.split[0].to_i
	y_coor = input.split[1].to_i
	if x_coor > maxX
		maxX = x_coor
	end
	if y_coor > maxY
		maxY = y_coor
	end
	if x_coor < minX
		minX = x_coor
	end
	if y_coor < minY
		minY = y_coor
	end
end
x = maxX - minX
y = maxY - minY
puts x > y ? x ** 2 : y ** 2

INF = 2e10;

def max(a, b)
  a > b ? a : b
end

def min(a, b)
  a < b ? a : b
end

n = gets.chomp.to_i
top = -INF
bottom = INF
right = -INF
left = INF

n.times do
  p = gets.chomp.split(" ").map{|str|str.to_i}

  top = max(top, p[1])
  bottom = min(bottom, p[1])
  right = max(right, p[0])
  left = min(left, p[0])
end

width = right - left
height = top - bottom

puts max(width, height) ** 2

n = STDIN.readline.to_i
x_min, y_min = 10**10, 10**10
x_max, y_max = -x_min, -y_min
n.times do
	x, y = STDIN.readline.split.map {|s| s.to_i }
	x_min = x if x < x_min
	y_min = y if y < y_min
	x_max = x if x > x_min
	y_max = y if y > y_min
end
a, b = x_max-x_min, y_max-y_min
puts [a, b].max**2

n= gets.to_i
mx,my,lx,ly=0,0,0,0
n.times do
  x,y = gets.split.map(&:to_i)
  mx = [mx,x].max
  my = [my,y].max
  lx = [lx,x].min
  ly = [ly,y].min
end
puts [mx-lx,my-ly].max**2

data = gets.to_i.times.map{gets.split.map{|x|x.to_i}}
min_x = data.min{|row| row[0]}[0]
max_x = data.max{|row| row[0]}[0]
min_y = data.min{|row| row[1]}[1]
max_y = data.max{|row| row[1]}[1]
result = [(max_x - min_x), (max_y - min_y)].max**2
puts result

def get_task_data(filename)
  raw_data = open(filename){|f|f.readlines}
  count = raw_data[0].to_i
  return false if count.zero?
  data = raw_data[1,raw_data.size].map{|str|str.split.map{|digit| digit.to_i}}
  return false if data.select{|row| row.size!=2}.any?
  return data.size==count ? data : false
end

def solve(filename)
  task_data = get_task_data filename
  return 0 unless task_data
  min_x = task_data.min{|row| row[0]}[0]
  max_x = task_data.max{|row| row[0]}[0]
  min_y = task_data.min{|row| row[1]}[1]
  max_y = task_data.max{|row| row[1]}[1]
  [(max_x - min_x), (max_y - min_y)].max**2
end

data = gets.to_i.times.map{gets.split.map{|x|x.to_i}}
puts data
min_x = data.map{|x|x[0]}.min
max_x = data.map{|x|x[0]}.max
min_y = data.map{|x|x[1]}.min
max_y = data.map{|x|x[1]}.max
puts "min_x:#{min_x} max_x:#{max_x} min_y:#{min_y} max_y:#{max_y}"
result = [(max_x - min_x), (max_y - min_y)].max**2
puts result

# 485B

min_x = min_y = 10 ** 9 + 1
max_x = max_y = -min_x
gets.to_i.times do
  x, y = gets.chomp.split.map &:to_i
  if x < min_x
    min_x = x
  elsif x > max_x
    max_x = x
  end
  if y < min_y
    min_y = y
  elsif y > max_y
    max_y = y
  end
end
puts [max_x - min_x, max_y - min_y].max ** 2

# 485B

min_x = min_y = 10 ** 9 + 1
max_x = max_y = -min_x
gets.to_i.times do
  x, y = gets.chomp.split.map &:to_i
  if x < min_x
    min_x = x
  end
  if x > max_x
    max_x = x
  end
  if y < min_y
    min_y = y
  end
  if y > max_y
    max_y = y
  end
end
p [min_x, max_x, min_y, max_y]
puts [max_x - min_x, max_y - min_y].max ** 2

n = gets.to_i
maxX = -10 ** 9
maxY = -10 ** 9
minX = 10 ** 9
minY = 10 ** 9
n.times do
	input = gets
	x_coor = input.split[0].to_i
	y_coor = input.split[1].to_i
	if x_coor > maxX
		max = x_coor
	end
	if y_coor > maxY
		maxY = y_coor
	end
	if x_coor < minX
		minX = x_coor
	end
	if y_coor < minY
		minY = y_coor
	end
end
x = maxX - minX
y = maxY - minY
puts x > y ? x ** 2 : y ** 2

n = gets.to_i
max = -10 ** 9
min = 10 ** 9
n.times do
	input = gets
	x_coor = input.split[0].to_i
	y_coor = input.split[1].to_i
	if x_coor > max
		max = x_coor
	elsif y_coor > max
		max = y_coor
	end
	if x_coor < min
		min = x_coor
	elsif y_coor < min
		min = y_coor
	end
end

puts (max - min) ** 2

n = gets.to_i
max = 0
n.times do
	input = gets
	x_coor = input.split[0].to_i
	y_coor = input.split[1].to_i
	if x_coor > max
		max = x_coor
	elsif y_coor > max
		max = y_coor
	end
end

puts max ** 2

n = gets.to_i
maxX = -10 ** 9
maxY = -10 ** 9
minX = 10 ** 9
minY = -10 ** 9
n.times do
	input = gets
	x_coor = input.split[0].to_i
	y_coor = input.split[1].to_i
	if x_coor > maxX
		max = x_coor
	end
	if y_coor > maxY
		maxY = y_coor
	end
	if x_coor < minX
		minX = x_coor
	end
	if y_coor < minY
		minY = y_coor
	end
end
x = maxX - minX
y = maxY - minY
puts x > y ? x ** 2 : y ** 2


def solve(a, b)
  a.gcd(b) == 1 ? "Finite" : "Infinite"
end

gets.strip.to_i.times do
  puts solve(*gets.strip.split(' ').map(&:to_i))
end

number_of_tests = gets.chomp.to_i

number_of_tests.times do
  a, b = gets.chomp.split.map(&:to_i)
  puts a.gcd(b) == 1 ? 'Finite' : 'Infinite'
end


/Variables:/
friends = 0
total_time = []
testcases = 0

/Prerequisites: Enter de numer of testcases/
testcases = Integer(gets.chomp)

/Firts: Request the number of friends to come/
for i in (0..(testcases-1))
    friends = Integer(gets.chomp)

    if friends <= 6
        friends = 6
    end
    if (friends%2)!=0
        friends = friends + 1
    end
    total_time[i] = (5*friends)/2
end
total_time.each do |elements|
    puts (elements)
end

gets
$stdin.map(&:to_i).each do |n|
  puts [(n + 1) / 2 * 5, 15].max
end

MOD = 10 ** 9 + 7
def gs; gets.chomp; end
def gi; gets.to_i; end
def gli; gets.split.map(&:to_i); end
def cyesno(x); puts x ? :Yes : :No; end
def uyesno(x); puts x ? :YES : :NO; end
def array_to_hash_by_count(c); Hash.new(0).tap { |x| c.each { |z| x[z] += 1 } }; end

def solve
  puts [((gi + 1) / 2) * 5 , 15].max
end

def main
  gi.times { solve }
end

main

/
Problem: Petya wants to order pizza for her birthday.
She does not know how much of her friends will come and
she wants to order so much pizza that each of his friends gets at least one slice of pizza.
The cooking time of the order is the total baking time of all the pizzas in the order.
Input
The first line contains a single integer t (1≤t≤104) — the number of testcases.
Each testcase consists of a single line that contains a single integer n (1≤n≤1016) — the number of Petya's friends.
Output
For each testcase, print one integer — the minimum number of minutes that is needed to bake pizzas containing at least n slices in total.
/
/Solution:/
/Declare the variables necessaries./
/Constants:/
SMALL_PIZZA = 6
MEDIUM_PIZZA = 8
LONG_PIZZA = 10
TIME_SMALL_PIZZA = 15
TIME_MEDIUM_PIZZA = 20
TIME_LONG_PIZZA = 25

/Variables:/
friends = 0
small_pizza_order = 1
medium_pizza_order = 0
long_pizza_order = 0
total_time = 0

condition = true
limit_small_pizza = false
limit_medium_pizza = false
limit_long_pizza = false

/Firts: Request the number of friends to come/
friends = Integer(gets.chomp)

/Second: Determinate the number of pizzas to order/
/In order to translate de minimun slides at one for friends, when it is one more slide than the number of friends, /
/it does not matter, because satisfate the condicion of minimun slides for person./
/So, for friends equals or less than 6, the case just be order a small pizza/

if friends <= 6
    /Case for small pizza:/
    small_pizza_order = 1
else
    /Other case/
    /We must to do a loop until aprox our value to the number of friends/
    while condition
        /For the max number of small pizza/
        if !limit_small_pizza
            /Sum one more pizza/
            small_pizza_order = small_pizza_order + 1
            /Quest if the number of slides is equals than the number of friends/
            if SMALL_PIZZA*small_pizza_order == friends || (SMALL_PIZZA*small_pizza_order) == (friends +1)
                limit_small_pizza = true
                limit_medium_pizza = true
                limit_long_pizza = true
                condition = false
            /Quest if is more than the number of friends/
            elsif SMALL_PIZZA*small_pizza_order > friends
                small_pizza_order = small_pizza_order - 2
                limit_small_pizza = true
            /Other case slides is small than friends and continue/
            end

        /For the max number of medium pizza/
        elsif !limit_medium_pizza
            /Sum one more pizza/
            medium_pizza_order = medium_pizza_order + 1
            /Quest if the number of slides is equals than the number of friends/
            if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order)-1) == friends
                limit_small_pizza = true
                limit_medium_pizza = true
                limit_long_pizza = true
                condition = false
            /Quest if is more than the number of friends/
            elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) > friends
                medium_pizza_order = medium_pizza_order - 2
                limit_medium_pizza = true
            /Other case slides is medium than friends and continue/
            end

        /For the max number of large pizza/
        elsif !limit_long_pizza
            /Sum one more pizza/
            long_pizza_order = long_pizza_order + 1
            /Quest if the number of slides is equals than the number of friends/
            if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order)-1) == friends
                limit_small_pizza = true
                limit_medium_pizza = true
                limit_long_pizza = true
                condition = false
            /Quest if is more than the number of friends/
            elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) > friends
                long_pizza_order = long_pizza_order - 1
                limit_long_pizza = true
                condition = false
            /Other case slides is large than friends and continue/
            end
        end
    end
end
total_time = TIME_SMALL_PIZZA*small_pizza_order + TIME_MEDIUM_PIZZA*medium_pizza_order + TIME_LONG_PIZZA*long_pizza_order
puts(total_time)

/
Problem: Petya wants to order pizza for her birthday.
She does not know how much of her friends will come and
she wants to order so much pizza that each of his friends gets at least one slice of pizza.
The cooking time of the order is the total baking time of all the pizzas in the order.
Input
The first line contains a single integer t (1≤t≤104) — the number of testcases.
Each testcase consists of a single line that contains a single integer n (1≤n≤1016) — the number of Petya's friends.
Output
For each testcase, print one integer — the minimum number of minutes that is needed to bake pizzas containing at least n slices in total.
/
/Solution:/
/Declare the variables necessaries./
/Constants:/
SMALL_PIZZA = 6
MEDIUM_PIZZA = 8
LONG_PIZZA = 10
TIME_SMALL_PIZZA = 15
TIME_MEDIUM_PIZZA = 20
TIME_LONG_PIZZA = 25

/Variables:/
friends = 0
small_pizza_order = 1
medium_pizza_order = 0
long_pizza_order = 0
total_time = 0

condition = true
limit_small_pizza = false
limit_medium_pizza = false
limit_long_pizza = false

/Firts: Request the number of friends to come/
puts("Enter the number of friends that will come to Petya party")
friends = Integer(gets.chomp)

/Second: Determinate the number of pizzas to order/
/In order to translate de minimun slides at one for friends, when it is one more slide than the number of friends, /
/it does not matter, because satisfate the condicion of minimun slides for person./
/So, for friends equals or less than 6, the case just be order a small pizza/

if friends <= 6
    /Case for small pizza:/
    small_pizza_order = 1
else
    /Other case/
    /We must to do a loop until aprox our value to the number of friends/
    while condition
        /For the max number of small pizza/
        if !limit_small_pizza
            /Sum one more pizza/
            small_pizza_order = small_pizza_order + 1
            /Quest if the number of slides is equals than the number of friends/
            if SMALL_PIZZA*small_pizza_order == friends || (SMALL_PIZZA*small_pizza_order) == (friends +1)
                limit_small_pizza = true
                limit_medium_pizza = true
                limit_long_pizza = true
                condition = false
            /Quest if is more than the number of friends/
            elsif SMALL_PIZZA*small_pizza_order > friends
                small_pizza_order = small_pizza_order - 2
                limit_small_pizza = true
            /Other case slides is small than friends and continue/
            end

        /For the max number of medium pizza/
        elsif !limit_medium_pizza
            /Sum one more pizza/
            medium_pizza_order = medium_pizza_order + 1
            /Quest if the number of slides is equals than the number of friends/
            if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order)-1) == friends
                limit_small_pizza = true
                limit_medium_pizza = true
                limit_long_pizza = true
                condition = false
            /Quest if is more than the number of friends/
            elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order) > friends
                medium_pizza_order = medium_pizza_order - 2
                limit_medium_pizza = true
            /Other case slides is medium than friends and continue/
            end

        /For the max number of large pizza/
        elsif !limit_long_pizza
            /Sum one more pizza/
            long_pizza_order = long_pizza_order + 1
            puts(long_pizza_order)
            /Quest if the number of slides is equals than the number of friends/
            if (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == friends || (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) == (friends +1) || ((SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order)-1) == friends
                limit_small_pizza = true
                limit_medium_pizza = true
                limit_long_pizza = true
                condition = false
            /Quest if is more than the number of friends/
            elsif (SMALL_PIZZA*small_pizza_order + MEDIUM_PIZZA*medium_pizza_order + LONG_PIZZA*long_pizza_order) > friends
                long_pizza_order = long_pizza_order - 1
                limit_long_pizza = true
                condition = false
            /Other case slides is large than friends and continue/
            end
        end
    end
end
total_time = TIME_SMALL_PIZZA*small_pizza_order + TIME_MEDIUM_PIZZA*medium_pizza_order + TIME_LONG_PIZZA*long_pizza_order
puts(total_time)


l, c = [], 0
gets.to_i.times do
  a, b = gets.split.map(&:to_f)
  l.push(a)
  l.push(b + 0.5)
end
l.sort!.each do |a|
  if a % 1 == 0
    c += 1
    break if c > 2
  else
    c -= 1
  end
end
puts c > 2 ? :NO : :YES

n = gets.to_i
shows = []
n.times do
  shows.push(gets.split.map(&:to_i))
end
shows.sort_by! { |start, _| start }

buffer = []
shows.each do |start, ending|
  buffer = buffer.select { |show| show[1] >= start } + [[start, ending]]
  break if buffer.count > 2
end
puts buffer.count > 2 ? "NO" : "YES"


n, k = readline.split(' ').collect(&:to_i)
a = readline.split(' ').collect(&:to_i)
b = readline.split(' ').collect(&:to_i)
down = 0
up = (b[0] + k) / a[0] + 1
while down + 1 < up
  mid = (down + up) / 2
  need = 0
  a.zip(b).each do |aa, bb|
    if aa * mid > bb
      need += aa * mid - bb
    end
  end
  if need <= k
    down = mid
  else
    up = mid
  end
end
puts down

input = gets.chomp.split(' ').map { |i| i.to_i }
ingredientNum, magicPowderNum = input[0], input[1]

input = gets.chomp.split(' ').map { |i| i.to_i }
needed = []

input.each do |item|
	needed << item
end

input = gets.chomp.split(' ').map { |i| i.to_i }
have = []

input.each do |item|
	have << item
end

nowMade = []

for i in (0...ingredientNum)
	nowMade << ((have[i] / needed[i]).floor)
end

=begin
nowMade.each do |i|
	puts "nowMade : #{i}"
end
=end

min = 0

until magicPowderNum <= 0
	min = nowMade.sort[0]
#	puts "min : #{min}"

	idx = nowMade.find_index { |i| i == min }

#	puts "idx : #{idx}"
	subVal = (needed[idx] - (have[idx] % needed[idx]))
	magicPowderNum -= subVal

	break if magicPowderNum < 0
	have[idx] += subVal
	nowMade[idx] += 1

#	puts "Remained : #{magicPowderNum}"
end

min = nowMade.sort[0]
puts min

parse_int = lambda { gets.split.map{|x| x.to_i} }

n, magic = parse_int.call
for_one = parse_int.call
havin = parse_int.call

cookies = 0

while true

  #puts havin.to_s
  #puts magic
  #puts

  n.times{ |_|
    havin[_] -= for_one[_]
    if havin[_] < 0
      magic += havin[_]
      havin[_] = 0
    end
  }
  break if magic < 0
  cookies += 1
end

print cookies


n = gets.to_i
if n%2==0
  puts "NO"
  exit
end
ans = []

# 以下で1から順番に入れる。
#1から反対側に飛ぶ。{右隣に1つ移動。反対側に飛ぶ}を繰り返す
ans[0] = 1
side_a = 0
side_b = n
2.step(n*2,2).with_index do |num, i|
  if i%2==0
    ans[side_b + i] = num
    ans[side_b+1 + i] = num+1
  else
    ans[side_a + i]= num
    ans[side_a+1 + i]= num+1
  end
end
puts "YES\n#{ans[0..(2*n-1)].join(' ')}"

n = gets.to_i
if n%2 == 0
  puts 'NO'
else
  puts 'YES'
  a = []
  (1..n).each do |x|
    if x%2 != 0
      a[x - 1] = 2*x - 1
      a[x - 1 + n] = 2*x
    else
      a[x - 1] = 2*x
      a[x - 1 + n] = 2*x - 1
    end
  end
  a.each {|x| print x, ' '}
end


gets.to_i.times do
  n, b, x, y = gets.split.map(&:to_i)
  a, sum = 0, 0
  n.times do
    if a + x <= b
      a += x
    else
      a -= y
    end
    sum += a
  end
  p sum
end

gets.to_i.times do
  n, b, x, y = gets.split.map(&:to_i)
  a, sum = 0, 0
  n.times do
    if a + x <= b && a + x - y <= b
      a += x
    else
      a -= y
    end
    sum += a
  end
  p sum
end

main = -> {
  t = int
  t.times do
      n, b, x, y = ints
      sum = 0
      cur = 0
      n.times do
          if cur + x <= b
              cur += x
          else
              cur -= y
          end
          sum += cur
      end
      puts sum
  end
}

DEBUG = true
MOD = 10**9+7
$yesno = %w(No Yes)
YesNo = %w(No Yes)
YESNO = %w(NO YES)
INF = 10**18

require "set"
require "prime"

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def strings; gets.to_s.split end
def rep(n, &b); Array.new(n, &b) end
def yes; puts $yesno[1] end
def no; puts $yesno[0] end
def yesno t; puts $yesno[t] end
def YesNo t; puts YesNo[t] end
def YESNO t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end
  def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
  def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main[]


#! /usr/bin/env ruby
# encoding: UTF-8

=begin
a = p q
b = q r

gcd = q
lcm = pqr
q(1+pr)

若偶数，直接输出 a=b=x/2
若奇数 > 1，必然有 1+pr > 1
若奇数 = 1，无解（题目保证>=2）

简化：令q === 1，则1+pr总是>1
=end

def solve
	n = gets.to_i
	#q = 1
	#p = 1
	#r = n-1 # ((n/q)-1 ) / p
	puts "#{1} #{n-1}"
end

gets.to_i.times{ solve }

1.upto(gets.to_i) do
  puts "1 #{gets.to_i - 1}"
end

t = gets.chomp.to_i
(0...t).each do |_|
  x = gets.chomp.to_i
  print 1, ' ', x-1
  puts
end

gets.to_i.times do
	x = gets.to_i
	puts [1, x-1].join(' ')
end

t = gets.to_i
t.times do
  x = gets.to_i
  puts [1, x-1].join(" ")
end

require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
t = gets.chomp.to_i

t.times do
  x = gets.chomp.to_i
  puts "#{x-1} #{1}"
end

T = gets.to_i

T.times do
  x = gets.to_i

  if x > 2 && x % 2 == 0
    puts "2 #{x - 2}"
  else
    puts "1 #{x - 1}"
  end
end

# cook your code here

n = gets.to_i;

(0..n-1).each do |i|
    x = gets.to_i;
    p 1, x-1;
end

# cook your code here

n = gets.to_i;

(0..n).each do |i|
    x = gets.to_i;
    p 1, x-1;
end

# cook your code here
x = gets.to_i;
p 1, x-1;


gets
a, b = 2.times.map{gets.split.map(&:to_i)}
c = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}
c.reject!{|j, i| j != c.min[0]}
p c.size
puts c.map(&:last) * ' '

n,m,k = gets.chomp.split(/ /).map!{|x|x.to_i}
ma = gets.chomp.split(/ /).map!{|x|x.to_i}
ka = gets.chomp.split(/ /).map!{|x|x.to_i}
summin = k+1
mas = Array.new
for i in 0..m-1
	sum = 0
	for j in 0..k-1
		sum += 1 if ka[j] % ma[i] == 0
	end
	if summin > sum
		mas.clear
		mas.push(i+1)
		summin = sum
	elsif summin == sum
		mas.push(i+1)
	end
end
puts mas.length
puts mas.join(' ')

gets
a, b = 2.times.map{gets.split.map(&:to_i).sort}
c = a.each_with_index.map{|j, i| [b.count{|k| k % j == 0}, i + 1]}
c.reject!{|j, i| j != c.min[0]}
p c.size
puts c.map(&:last) * ' '


layout1 = gets.chomp
layout2 = gets.chomp
s = gets.chomp

res = ''
s.split("").each do |c|
    i = layout1.index(c.downcase)
    unless i
        res += c
    else
        if c == c.upcase
            res += layout2[i].upcase
        else
            res += layout2[i]
        end
    end
end
puts res

first=gets.chomp
second=gets.chomp
third=gets.chomp

third.each_char do |x|
if x=~/[[:digit:]]/
    print x
    next
end
index = first.index(x.downcase)

if x == x.upcase
    print second[index].upcase
else
    print second[index]
    end
end

a = gets
b = gets
h = {}
(0...26).each { |i| h[a[i]] = b[i] }
puts gets.chomp('').split('').map { |x|
  c = h[x.downcase] || x
  x =~ /[A-Z]/ ? c.upcase : c
}.join

k1 = gets.chomp
k2 = gets.chomp

map = {}
for i in 0 ... 26
  map[k1[i]] = k2[i]
end

s = gets.chomp
t = s.split('').map{|c|
  if c != c.downcase
    map[c.downcase].upcase
  else
    map[c] ? map[c] : c
  end
}.join()
puts t

a,b,c=$<.map &:chomp
puts c.tr(a+a.upcase,b+b.upcase)

#!/usr/bin/ruby -w

class String

  def is_upper?
    not self.match /[[:lower:]]/
  end

  def is_lower?
    not self.match /[[:upper:]]/
  end

end

str1 = gets
str2 = gets
strr = gets

str_siz = strr.size
str_siz.times do |i|
  idx = str1.index(strr[i].downcase)
  if idx != nil then
    if strr[i].is_upper? then
      strr[i] = str2[idx].capitalize
    else
      strr[i] = str2[idx]
    end
  end
end
puts strr

fs = gets.chomp
ss = gets.chomp
fsl = fs.upcase
ssl = ss.upcase

ans = ''
gets.chomp.chars.each do |s|
  if id = fs.index(s)
    ans += ss[id]
  elsif id = fsl.index(s)
    ans += ssl[id]
  else
    ans += s
  end
end

puts ans

f = gets.strip.split("")
s = gets.strip.split("")
t = gets.strip
ans = ""
t.each_char do |c|
    id = f.index c.downcase
    if /[[:upper:]]/.match c
        ans += s[id].upcase
    elsif /[[:digit:]]/.match c
        ans += c
    else
        ans += s[id]
    end
end
puts ans

str1=gets.chomp
str2=gets.chomp

hs={}
str1.size.times{|i|
	e1=str1[i]
	e2=str2[i]
	hs[e1]=e2
	hs[e1.upcase]=e2.upcase
}
str3=gets.chomp
str3.chars.each{|e|
	if hs.member?(e)==false
		print e
	else
		print hs[e]
	end
}
print "\n"

a = gets.chomp!
b = gets.chomp!
t = gets.chomp!

h = Hash.new
26.times do |i|
	h[a[i]] = b[i]
end

f = ""
t.chars do |c|
	if c == c.downcase
		f.insert(-1, h[c] || c)
	else
		f.insert(-1, h[c.downcase].upcase)
	end
end

puts f

a,b,c=$<.map &:chomp
puts c.tr(b+b.upcase,a+a.upcase)

#!/usr/bin/ruby -w

class String

  def is_upper?
    not self.match /[[:lower:]]/
  end

  def is_lower?
    not self.match /[[:upper:]]/
  end

end

puts 'Hello World'

str1 = gets
str2 = gets
strr = gets

str_siz = strr.size
str_siz.times do |i|
  idx = str1.index(strr[i].downcase)
  if idx != nil then
    if strr[i].is_upper? then
      strr[i] = str2[idx].capitalize
    else
      strr[i] = str2[idx]
    end
  end
end
puts strr


s,m,n=0,1e6,Array.new(n=gets.to_i){gets.split.map(&:to_i)[1..-1].sort}
(n+n[0,2]).each_cons(3){|a,b,c|r,b,*e=b.dup
b&&(a,*w=a.drop_while{|i|i<r};a||=m
c,*r=c.drop_while{|i|i<r};c||=m
g=h=0
loop{b>a||b>c ? (a>b ? (h+=1;c=r.shift||m):(g+=1;a=w.shift||m)):(g!=h&&s+=1
b>m||(g=h;break if !b=e.shift))})}
p s

#require "profile"

time = Time.now

STDOUT.sync = true

net = Array.new(n = gets.to_i) do
    gets " "
    gets.split.map(&:to_i).sort
end

net += net.take(2)

s = 0

net.each_cons(3) do |l1t,l2t,l3t| #puts [l2t].inspect
    l2 = l2t.dup; start = l2.shift; #puts start
    l1 = l1t.dup; l1 = l1.drop_while{ |i| i < start }
    l3 = l3t.dup; l3 = l3.drop_while{ |i| i < start }
    a = l1.shift || 1000000
    next unless b = l2.shift
    c = l3.shift || 1000000
    g1 = g2 = 0
    loop do
        #puts [a,b,c,g1,g2,s].inspect
        if b <= a && b <= c
            if b == 1000000
                s += 1 if g1 != g2
                break
            end
            #puts "b"
            s += 1 if g1 != g2
            g1 = g2 = 0
            break unless b = l2.shift
        elsif a <= b && a <= c
            #puts "a"
            g1 += 1
            a = l1.shift || 1000000
        else
            #puts "c"
            g2 += 1
            c = l3.shift || 1000000
        end
    end
    #puts s
end

puts s

#puts Time.now - time

n = (1..(n=gets.to_i)).map do
    gets.split.map(&:to_i).drop(1).sort
end

s = 0
m = 1e6

(n + n[0,2]).each_cons(3) do |a,b,c|
    r,b,*e = b.dup
    next if !b
    a,*w = a.dup.drop_while{ |i| i < r }; a ||= m
    c,*r = c.dup.drop_while{ |i| i < r }; c ||= m
    g = h = 0
    loop do
        b <= a && b <= c ? (
            s += 1 if g != h
            (b <= m) && ( g = h; break if !b = e.shift )
        ) : a <= b && a <= c ?
        ( g += 1; a = w.shift || m ) :
        ( h += 1; c = r.shift || m )
    end
end

puts s

#require "profile"

time = Time.now

STDOUT.sync = true

net = Array.new(n = gets.to_i) do
    gets " "
    gets.split.map(&:to_i).sort
end

net += net.take(2)

s = 0

net.each_cons(3) do |l1t,l2t,l3t| #puts [l2t].inspect
    l2 = l2t.dup; start = l2.shift; #puts start
    l1 = l1t.dup; l1 = l1.drop_while{ |i| i < start }
    l3 = l3t.dup; l3 = l3.drop_while{ |i| i < start }
    a = l1.shift || 1000000
    next unless b = l2.shift
    c = l3.shift || 1000000
    g1 = g2 = 0
    loop do
        #puts [a,b,c,g1,g2,s].inspect
        if b <= a && b <= c
            if b == 1000000
                s += 1 if g1 != g2
                break
            end
            #puts "b"
            s += 1 if g1 != g2
            g1 = g2 = 0
            break unless b = l2.shift
        elsif a <= b && a <= c
            #puts "a"
            g1 += 1
            a = l1.shift || 1000000
        else
            #puts "c"
            g2 += 1
            c = l3.shift || 1000000
        end
    end
    #puts s
end

puts s

puts Time.now - time


n, m, k = gets.split.map(&:to_i)
$socks = [nil] + gets.split.map(&:to_i)
days = m.times.map{gets.split.map(&:to_i)}

$visited = Array.new(n + 1)
$e = Array.new(n + 1){Array.new}

days.each do |l, r|
  $e[l] << r
  $e[r] << l
end

def bfs(u)
  todo = []
  push = lambda do |v|
    $visited[v] = true
    todo << v
  end
  push.(u)
  while u = todo.shift
    $rainbow[$socks[u]] += 1
    $e[u].each do |v|
      next if $visited[v]
      push.(v)
    end
  end
end

ans = 0
1.upto(n) do |i|
  next if $visited[i]
  $rainbow = Hash.new(0)
  bfs(i)
  v = $rainbow.values
  ans += v.inject(:+) - v.max
end

puts ans

def solve
  n, m, k = gets.split.map(&:to_i)
  cs = gets.split.map(&:to_i)
  uf = UnionFind.new(n)
  m.times do
    l, r = gets.split.map(&:to_i)
    uf.unit(l - 1, r - 1)
  end
  g2c = {}
  cs.each_with_index do |e, i|
    x = uf.find(i)
    colors = (g2c[x] ||= {})
    colors[e] ||= 0
    colors[e] += 1
  end
  ans = 0
  g2c.each_value do |colors|
    vs = colors.values
    sum = vs.inject(0, &:+)
    max = vs.max
    ans += sum - max
  end
  puts ans
end

class UnionFind
  def initialize(size)
    @parent = (0...size).to_a
    @rank = Array.new(size, 0)
  end

  def find(x)
    return x if @parent[x] == x
    return (@parent[x] = find(@parent[x]))
  end

  def unit(x, y)
    x, y = find(x), find(y)
    return if x == y
    if @rank[x] < @rank[y]
      @parent[x] = y
    else
      @parent[y] = x
      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same(x, y)
    find(x) == find(y)
  end
end

solve

# TEMPLATE BEGIN
def read_vector
    gets.chomp.split(/\s+/)
end
def read_vector_int
    read_vector.map(&:to_i)
end
# TEMPLATE END

class SNM
    def initialize(n)
        @a = (0..n).to_a
    end

    def get(v)
        while @a[v] != v
            @a[v] = @a[@a[v]]
            v = @a[v]
        end
        return v
    end

    def join(u, v)
        pu = get(u)
        pv = get(v)
        return if pu == pv
        if rand < 0.5
            @a[pu] = @a[pv]
        else
            @a[pv] = @a[pu]
        end
    end
end

n, m, k = read_vector_int
colors = [nil] + read_vector_int

snm = SNM.new(n)
m.times.each do
    v, u = read_vector_int
    snm.join(v, u)
end

colors_in_comp = Array.new(n + 1) { [] }
(1..n).each do |id|
    comp_id = snm.get(id)
    colors_in_comp[comp_id].push(colors[id])
end

ans = 0
colors_in_comp.each do |c|
    next if c.empty?

    cnt = Hash.new(0)
    c.sort!
    c.each{ |col| cnt[col] += 1 }
    max_cnt = cnt.values.max
    ans += c.size - max_cnt
end

puts ans


a=gets.chomp.split(" ")
n=a[0].to_i
m=a[1].to_i
i=1
p=2
n.times do
    if (i+2*n)<=m
        print "#{i+2*n} "
    end
    if i<=m
        print "#{i} "
    end

    i+=2
     if (p+2*n)<=m
        print "#{p+2*n} "
    end
     if p<=m
        print "#{p} "
    end

    p+=2
end

n, m = readline.split(' ').collect(&:to_i)
arr = []
1.upto(n) do |i|
  arr += [i * 2 - 1 + n * 2, i * 2 - 1, i * 2 + n * 2, i * 2]
end
arr.keep_if {|num| num <= m}
arr.each_with_index do |num, ind|
  if ind != 0
    print " "
  end
  print num
end
puts ""

n,m=gets.split.map(&:to_i)
a=[*1..(m+3)/4*4].each_slice(2).each_slice(n).to_a
puts a.shift.zip(*a).flat_map{|(a,b),(c,d)|[c,a,d,b]}.select{|e|e&&e<=m}*' '

#!/usr/bin/ruby
n,m=gets.split.map(&:to_i)
m0=(m+3)/4
puts [*1..m0*4].each_slice(2).each_slice(m0).to_a.transpose.flat_map{|(a,b),(c,d)|[c,a,d,b]}.select{|e|e<=m}*' '


require "pp"

class Edge
  def initialize (src,dst,cost)
    @src = src
    @dst = dst
    @cost = cost
  end

  attr_accessor :src, :dst, :cost
end

edges = Array.new
num = gets.to_i
cost = 0

for i in 0..num-1
	ary = gets.split.map{|elem| elem.to_i}
	edges << Edge.new(ary[0],ary[1],ary[2])
	cost += ary[2]
end

first = edges.shift
arc = Edge.new(first.src,first.dst,0)

while edges.length > 0
	edges.each_with_index do |edge, i|
		if edge.src == arc.dst
			arc.dst = edge.dst
			edges.delete_at(i)
		elsif edge.dst == arc.dst
			arc.dst = edge.src
			arc.cost += edge.cost
			edges.delete_at(i)
		end
	end
end

p [arc.cost,cost - arc.cost].min

h=Array.new(gets.to_i){[]}
while gets
a,b,c=$_.split.map &:to_i
h[a-1]<<[b-1,0]
h[b-1]<<[a-1,c]
end
p h[0].map{|a,s|x=0
while a>0
h[a].map{|b,c|if b!=x
a,x=b,a
s+=c
break
end}
end
s}.min

#!/usr/bin/ruby

N = gets.to_i

cities = Array.new(N + 1) {Array.new}

N.times do
  (a, b, c) = gets.split.map{|e| e.to_i}

  cities[a].push [b, 0]
  cities[b].push [a, c]
end

prev = 1
now = cities[1][0][0]
cost0 = cities[1][0][1]

(N - 1).times do # not N - 2
  id = (cities[now][0][0] == prev) ? 1 : 0
  prev = now
  cost0 += cities[now][id][1]
  now = cities[now][id][0]
end

prev = 1
now = cities[1][1][0]
cost1 = cities[1][1][1]

(N - 1).times do # not N - 2
  id = (cities[now][0][0] == prev) ? 1 : 0
  prev = now
  cost1 += cities[now][id][1]
  now = cities[now][id][0]
end

puts [cost0, cost1].min

p = Array.new(101)
101.times{|i|
  p[i]=Array.new(101,0)
}

def find_cost(prev, now, n, p)
  res, d = 0, p[prev][now]
  #puts "find_cost: "+prev.to_s+" "+now.to_s
  res = res - d if (d<0)
  return res if (now==1)
  (1..n).each{|i|
    res += find_cost(now, i, n, p) if (p[now][i].to_i!=0)&&(i!=prev)
  }
  res
end

n = gets.chomp.to_i

n.times { |i|
  a,b,c = gets.chomp.split(' ').map{|it| it.to_i}
  p[a][b], p[b][a] = c, -c
}

ans = -1

(2..n).each{|i|
  if p[1][i]!=0
    candidate = find_cost(1, i, n, p)
    ans = candidate if (ans==-1  ||  candidate < ans)
  end
}

puts ans

h=Array.new(gets.to_i){[]}
while gets
  a,b,c=$_.split.map &:to_i
  h[a-1]<<[b-1,0]
  h[b-1]<<[a-1,c]
end
p h[0].map{|a,s|x=0
  while a>0
    h[a].map{|b,c|
      if b!=x
        a,x=b,a
        s+=c
        break
      end
    }
  end
  s
}.min

# start 2010/7/28 17:11
# implementation finish at 18:57

#ring_road

class Edge
  def initialize(u,v,inv_cost)
    @src = u
    @dst = v
    @inv_cost = inv_cost
  end

  attr_accessor :src, :dst, :inv_cost
end

#f = open("hoge.txt")

num = gets.to_i
#num = f.gets.to_i
#p num

edges = Array.new
edge_subsets = Array.new

total_cost = 0

for i in 0..num-1
	#ary = f.gets.split.map {|elem| elem.to_i}
	ary = gets.split.map {|elem| elem.to_i}
	# p ary

	# e(u,v)  ,  inv_cost_of_e �Ƃ���format.
	edges << Edge.new(ary[0],ary[1],ary[2])

	total_cost += ary[2]
end

#circle�����
	#edge��subset������čs���Amerge���Ă���

edges.each {|edge|
	if edge_subsets.length == 0
		subset = Array.new
		subset << edge.src << edge.dst
		edge_subsets << subset
	else
		merge_flg = false

		edge_subsets.each{|subset|
			merge_flg = true

			if edge.src == subset.first
				subset.unshift edge.dst
			elsif edge.src == subset.last
				subset << edge.dst
			elsif edge.dst == subset.first
				subset.unshift edge.src
			elsif edge.dst == subset.last
				subset << edge.src
			else
				merge_flg = false
			end

			if merge_flg
				break
			end
		}

		unless merge_flg
			subset = Array.new
			subset << edge.src << edge.dst
			edge_subsets << subset
		end
	end
}

#p edge_subsets

#subset���m��merge

#puts "merge subsets"

while edge_subsets.length > 1
	temp_ss = edge_subsets.pop

	edge_subsets.each{|subset|
		if temp_ss.first == subset.first
			temp_ss.reverse!
			temp_ss.pop
			subset = temp_ss + subset
		elsif temp_ss.first == subset.last
			temp_ss.shift
			subset.concat temp_ss
		elsif temp_ss.last == subset.first
			temp_ss.pop
			subset = temp_ss + subset
		elsif temp_ss.last == subset.last
			temp_ss.reverse!
			temp_ss.shift
			subset.concat temp_ss
		end
	}
end

#p edge_subsets

circle = edge_subsets.pop
#p circle

rev_cost = 0

edges.each {|edge|
	idx = circle.index(edge.src)
	if circle[idx+1] != edge.dst
		#p edge
		rev_cost += edge.inv_cost
	end
}

alt = total_cost - rev_cost
if rev_cost < alt
	p rev_cost
else
	p alt
end

=begin

[4, 6, 1, 5, 3, 2]

---
n=6

1 5
5 3

2 4

1 6

2 3
4 6

=end

num_of_edge = gets
edge_list = []
while line = gets
	obj = {}
	obj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}
	edge_list << obj
end
cost_pair = [0,0]
ring_obj = edge_list.pop
cost_pair[0] += ring_obj[:cost]

while edge_list.length > 0
	del_obj = edge_list.find{|obj|
		if    obj[:start] == ring_obj[:dest]
			ring_obj[:dest] = obj[:dest]
			cost_pair[0] += obj[:cost]
		elsif obj[:dest] == ring_obj[:dest]
			cost_pair[1] += obj[:cost]
			ring_obj[:dest] = obj[:start]
		end
	}
	edge_list.delete(del_obj)
end
puts cost_pair.min

__END__
6
1 5 4
5 3 8
2 4 15
1 6 16
2 3 23
4 6 42

def dfs(u, g, used)
  used[u], result = true, 0
  g[u].each do |v, cost|
    result += cost + dfs(v, g, used) unless used[v]
  end
  result
end

def solve(n, g)
  left, right = g[0]

  g[0] = [left]
  alpha = dfs(0, g, Array.new(n, false)) + g[right.first].assoc(0)[-1]

  g[0] = [right]
  beta = dfs(0, g, Array.new(n, false)) + g[left.first].assoc(0)[-1]

  [alpha, beta].min
end

n = gets.to_i
g = Array.new(n) { [] }

n.times do
  a, b, c = gets.split.map { |v| v.to_i }
  a -= 1
  b -= 1
  g[a] << [b, 0]
  g[b] << [a, c]
end

puts solve(n, g)

def dfs(u, g, used)
  used[u] = true
  result = 0
  g[u].each do |v, cost|
    result += cost + dfs(v, g, used) unless used[v]
  end
  result
end

def solve(n, g)
  left, right = g[0]

  g[0] = [left]
  alpha = dfs(0, g, Array.new(n, false)) + g[right.first].assoc(0)[-1]

  g[0] = [right]
  beta = dfs(0, g, Array.new(n, false)) + g[left.first].assoc(0)[-1]

  [alpha, beta].min
end

n = gets.to_i
g = Array.new(n) { [] }

n.times do
  a, b, c = gets.split.map { |v| v.to_i }
  a -= 1
  b -= 1
  g[a] << [b, 0]
  g[b] << [a, c]
end

puts solve(n, g)

def dfs(u, g, used)
  used[u] = true
  result = 0
  g[u].each do |pair|
    v, cost = pair
    result += cost + dfs(v, g, used) if not used[v]
  end
  result
end

def solve(n, g)
  first, last = g[0]

  g[0] = [first]
  alpha = dfs(0, g, Array.new(n, false)) + g[last.first].assoc(0)[-1]

  g[0] = [last]
  beta = dfs(0, g, Array.new(n, false)) + g[first.first].assoc(0)[-1]

  [alpha, beta].min
end

n = gets.to_i
g = Array.new(n) { [] }

n.times do
  a, b, c = gets.split.map { |v| v.to_i }
  a -= 1
  b -= 1
  g[a] << [b, 0]
  g[b] << [a, c]
end

puts solve(n, g)

def gao(e, v, p)
	e[v].map{|w, c| w == p ? 0 : c + gao(e, w, v)}.inject(&:+)
end

n = gets.to_i
e = Array.new(n + 1){[]}
y = 0
(n - 1).times do
	a, b, c = gets.split.map(&:to_i)
	e[a] << [b, 0]
	e[b] << [a, c]
	y += c
end
a, b, c = gets.split.map(&:to_i)
x = gao(e, a, -1)
p [x + c, y - x].min

n=gets.to_i
g=Array.new(n){[]}
n.times{
    input=gets.split.map(&:to_i)
    a=input[0]-1
    b=input[1]-1
    c=input[2]
    g[a].push([a,b,c])
    g[b].push([a,b,c])
}
res=[]
for q in 0..1
    cost=0
    v=g[0][q][1]
    if v==0 then
        cost+=g[0][q][2]
        v=g[0][q][0]
    end
    back=g[0][q]
    loop do
        if v==0 then
            break
        end
        for i in 0..1
            if g[v][i]!=back then
                back=g[v][i]
                if g[v][i][1]==v then
                    cost+=g[v][i][2]
                    v=g[v][i][0]
                else
                    v=g[v][i][1]
                end
                break
            end
        end
    end
    res.push(cost)
end
puts res.min

num_of_edge = gets.to_i
edge_list = []
ring_hash = Hash.new
while line = gets
	obj = {}
	obj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}
	edge_list << obj
end

edge_list.each{|obj|
	if !ring_hash.include?(obj[:start])
		ring_hash[ obj[:start] ] = obj[:dest]
		obj[:clock_wise] = true
	else
		ring_hash[ obj[:dest] ]  = obj[:start]
	end
}
puts [ edge_list.select{|obj| obj[:clock_wise] }.inject(0){|sum, obj| sum += obj[:cost] } , edge_list.select{|obj| !obj[:clock_wise] }.inject(0){|sum, obj| sum += obj[:cost] } ].min

num_of_edge = gets.to_i
edge_list                = []
clock_wise_edge_list     = []
non_clock_wise_edge_list = []
ring_hash = Hash.new
while line = gets
	obj = {}
	obj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}
	edge_list << obj
end
edge_list.each{|obj|
	if !ring_hash.include?(obj[:start])
		ring_hash[ obj[:start] ] = obj[:dest]
		clock_wise_edge_list << obj
	else
		ring_hash[ obj[:dest] ]  = obj[:start]
		non_clock_wise_edge_list << obj
	end
}
puts [ clock_wise_edge_list.inject(0){|sum, obj| sum += obj[:cost] } , non_clock_wise_edge_list.select{|obj| !obj[:clock_wise?] }.inject(0){|sum, obj| sum += obj[:cost] } ].min

num_of_edge = gets.to_i
edge_list = []
ring_hash = Hash.new
while line = gets
	obj = {}
	obj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}
	edge_list << obj
end
edge_list.each{|obj|
	if ring_hash.value?(obj[:start])
		ring_hash[ obj[:start] ] = obj[:dest]
	elsif ring_hash.key?(obj[:start])
		ring_hash[ obj[:dest] ]  = obj[:start]
		obj[:reverse] = true
	else
		ring_hash[ obj[:start] ] = obj[:dest]
	end
}
puts [ edge_list.select{|obj| obj[:reverse] }.inject(0){|sum, obj| sum += obj[:cost] } , edge_list.select{|obj| !obj[:reverse] }.inject(0){|sum, obj| sum += obj[:cost] } ].min

gets
edge_list = []
ring_hash = Hash.new
while line = gets
	obj = {}
	obj[:start], obj[:dest], obj[:cost] = line.chomp.split.map{|s| s.to_i}
	edge_list << obj
end
edge_list.each{|obj|
	if !ring_hash.include?(obj[:start])
		ring_hash[ obj[:start] ] = obj[:dest]
		obj[:clock_wise?] = true
	else
		ring_hash[ obj[:dest] ]  = obj[:start]
	end
}
puts [ edge_list.select{|obj| obj[:clock_wise?] }.inject(0){|sum, obj| sum += obj[:cost] } , edge_list.select{|obj| !obj[:clock_wise?] }.inject(0){|sum, obj| sum += obj[:cost] } ].min


s = gets.chomp.split(/[,;]/, -1)
number = []
nonnumber = []
s.each do |w|
  if w.match(/^[0-9]+$/) then
    if w.length >= 2 and w[0] == "0" then
      nonnumber << w
    else
      number << w
    end
  else
    nonnumber << w
  end
end
if number.length == 0 then
  puts "-"
else
  p number.join(",")
end
if nonnumber.length == 0 then
  puts "-"
else
  p nonnumber.join(",")
end

str = gets
words = str.split(/,|;/)
words[words.length-1] = words[words.length-1][0...words[words.length-1].length-1]
nums = []
others = []
words.each do |word|
	if word.to_i.to_s == word
		nums.push(word)
	else
		others.push(word)
	end
end
if nums.empty?
	puts "-"
else
	puts "\"#{nums.join(',')}\""
end
if others.empty?
	puts "-"
else
	puts "\"#{others.join(',')}\""
end

str = gets
str = str[0...str.length-1]
words = str.split(/,|;/)
nums = []
others = []
words.each do |word|
	if word.to_i.to_s == word
		nums.push(word)
	else
		others.push(word)
	end
end
if nums.empty?
	puts "-"
else
	puts "\"#{nums.join(',')}\""
end
if others.empty?
	puts "-"
else
	puts "\"#{others.join(',')}\""
end


1.upto(gets.to_i) do
  n = gets.to_i

  if n == 1
    puts -1
    next
  end

  if (2*(n-1) + 3).modulo(3).zero?
    puts '2' * (n-2) + '33'
  else
    puts '2' * (n-1) + '3'
  end
end

T = gets.to_i

T.times do
  n = gets.to_i

  if n == 1
    puts -1
  else
    puts '2' + '3' * (n - 1)
  end
end

def main
  t = gets.chomp.to_i
  t.times { solve }
end

def solve
  n = gets.chomp.to_i
  # a, b, c = gets.chomp.split.map(&:to_i)
  # S = gets.chomp.chars
  # p n
  # p [a, b, c]
  if n == 1
    p(-1)
  else
    ans = "5" * (n-1)
    ans += "4"
    print (ans + "\n")
  end
end

main

t = gets.to_i
t.times do
  n = gets.to_i
  if n == 1
    puts -1
  else
    case n % 3
    when 0
      puts "2" * (n - 1) + "3"
    when 1
      puts "2" * (n - 2) + "33"
    when 2
      puts "2" * (n - 1) + "3"
    end
  end
end

#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/1326/A

n = gets.to_i

n.times do
  a = gets.to_i

  if a == 1
    puts '-1'
  else
    puts ('9' * (a - 1) + '8')
  end
end

def main
  t = gets.chomp.to_i
  t.times { solve }
end

def solve
  n = gets.chomp.to_i
  # a, b, c = gets.chomp.split.map(&:to_i)
  # S = gets.chomp.chars
  # p n
  # p [a, b, c]
  if n == 1
    p(-1)
  else
    ans = "2" * (n-1)
    ans += "9"
    print (ans + "\n")
  end
end

main


gets.to_i.times do
  n, m = gets.split.map(&:to_i)
  xxs = n.times.map { gets.chomp }
  i, j = xxs.filter_map.with_index do |xs, i|
    if j = xs.index("R")
      [i, j]
    end
  end.first
  if xxs[...i].join.include?("R") || xxs.map { |xs| xs[...j] }.join.include?("R")
    puts "NO"
  else
    puts "YES"
  end
end

def solve(n,m,a)
  0.upto(n-1) do |i|
    0.upto(m-1) do |j|
      if a[i][j] == 'R' then
        c = 0
        0.upto(n-1) do |k|
          0.upto(m-1) do |l|
            if a[k][l] == 'R' and ((k<i) or (l<j))
              c += 1
            end
          end
        end
        #puts "#{i} #{j} #{c}"
        return "YES" if c == 0
      end
    end
  end
  return "NO"
end

gets.to_i.times do
  n,m = gets.chomp.split.map(&:to_i)
  a = []
  n.times do |i|
    a[i] = gets.chomp.split('')
  end
  puts solve(n,m,a)
end

def get_top_left_robot(a)
  a.each_with_index do |sub, r|
    sub.each_char.with_index do |v, c|
      if v == 'R'
        return r, c
      end
    end
  end
end

def move(a, n, m)
  row, col = get_top_left_robot(a)

  (row+1..n-1).each do |r|
    (0..col-1).each do |c|
      return "NO" if a[r][c] == 'R'
    end
  end

  "YES"
end

t = gets.chomp.to_i
ans = []

t.times do
  n, m = gets.chomp.split.map(&:to_i)
  a = []
  n.times do
    a << gets.chomp
  end

  ans << move(a, n, m)
end

puts ans


gets.to_i.times {
  gets
  counts = Array.new(2, 0)
  gets.split.map { |v|
    v = v.to_i
    counts[v % 2] += 1
  }
  if counts[1] == 0 or counts[0] == 0 and counts[1] % 2 == 0
    puts "NO"
  else
    puts "YES"
  end
}

t = gets.to_i
(1).upto(t) do
  n = gets.to_i
  a = gets.split(' ').map(&:to_i)
  odd=false
  even = false
  a.each do |i|
    odd = true if(i&1)==1
    even = true if(i&1)==0
  end
  if odd and even
    puts "YES"
  elsif odd and (n&1)==1
    puts"YES"
  else
    puts "NO"
  end
end

gets.to_i.times do
	n = gets.to_i
	a = gets.split.map &:to_i
	sum = a.inject(:+)
	if sum % 2 == 1
		puts "YES"
	else
		odd = a.count{|i| i % 2 == 1}
		even = n - odd
		puts odd > 0 && even > 0 ? "YES" : "NO"
	end
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
t.times {
    n = gets.to_i
    a = gets.split.map(&:to_i)
    evens, odds = a.count(&:even?), a.count(&:odd?)
    if odds.odd?
        puts "YES"
    else
        if evens > 0 && odds > 0
            puts "YES"
        else
            puts "NO"
        end
    end
}

1.upto(gets.to_i) do
  gets
  a = gets.split(' ').map(&:to_i)

  result = a.inject(&:+).odd? || (a.any?(&:odd?) && a.any?(&:even?))

  puts result ? 'YES' : 'NO'
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
t.times {
    n = gets.to_i
    a = gets.split.map(&:to_i)
    evens, odds = a.count(&:even?), a.count(&:odd?)
    if odds.odd?
        puts "YES"
    else
        puts "NO"
    end
}


#Infinity
#geti,getia
#Object # dcopy
#
#String # to_a
#   "abc".to_a #=> ["a","b","c"]
#String # to_ia
#   "1 2 3".to_ia #=> [1,2,3]
#
#Array # rsort,rsort!
#   [1,3,2,4].rsort #=> [4,3,2,1]
#
#Integer # divisor
#   24.divisor #=> [1,2,3,4,6,8,12,24]
#
include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0
class Matrix;def inspect;empty? ? "Matrix.empty(#{row_size}, #{column_size})":"Matrix[\n#{@rows.map(&:inspect).join("\n")}\n]";end;end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_a;split("");end;end
class String;def to_ia;split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end
class Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end

n = geti
px = []
py = []
res = 0
n.times{
    p = getia
    res += (p[0]**2 + p[1]**2) * (n - 1)
    px.push p[0]
    py.push p[1]
}
xs = px.inject(&:+)
xx = 0
px.each{|x| xx += x * (xs - x) }
ys = py.inject(&:+)
yy = 0
py.each{|y| yy += y * (ys - y) }

p res - xx - yy

def solve(x,n)
    sum=0
    ans=0
    x.each{|i| sum+=i}
    x.each{|i|
        ans+=(n-1)*i*i-(sum-i)*i
    }
    ans
end

n=gets.to_i
x=Array.new(n,0)
y=Array.new(n,0)
n.times{|i|
    input=gets.split.map(&:to_i)
    x[i]=input[0]
    y[i]=input[1]
}

p solve(x,n)+solve(y,n)

n=gets.to_i
sigx1,sigx2,sigy1,sigy2=[0,0,0,0]
n.times do
    a,b=gets.split.map(&:to_i)
    sigx1+=a
    sigx2+=a*a
    sigy1+=b
    sigy2+=b*b
end
p n*(sigx2+sigy2)-sigx1**2-sigy1**2


n = gets.to_i
a = ['C', '.']
s = []
(n / 2 + 1).times do
  s << a
end
s = s.join("").chars
puts (n * n + 1) / 2
n.times do |i|
  puts s[(i % 2)...(i % 2 + n)].join("")
end

n = gets.chomp().to_i
if (n % 2 == 0)
	puts(n*n/2)
else
	puts((n-1)*n/2 + (n+1)/2)
end
for i in 1..n
	for j in 1..n
		if i%2 == j%2
			print 'C'
		else
			print '.'
		end
	end
	puts
end

n = gets.to_i
res =  n ** 2 / 4  + (n + 1) / 2 * (n / 2)
puts n.even? ? res : res + 1
n.times do |i|
  if i.even?
    puts ("C." * ((n + 1) / 2)).slice(0..n - 1)
  else
    puts (".C" * ((n + 1) / 2)).slice(0..n - 1)
  end
end

n = gets.to_i

ans = []
n.times do |i|
  if i.even?
    ans << "C." * (n/2) + "C" * (n%2)
  else
    ans << ".C" * (n/2) + "." * (n%2)
  end
end
puts n ** 2 / 2 + n % 2
puts ans

n=gets.to_i
if n%2==0 then
	puts n/2*n
else
	puts n*(n/2)+(n/2+1)
end

n.times{|i|
	n.times{|j|
		if (i+j)%2==0 then
			print "C"
		else
			print "."
		end
	}
	puts ""
}

n = STDIN.gets.to_i
v1 = (n.to_f / 2).floor
v2 = (n.to_f / 2).ceil
puts v1*v1 + v2*v2
lineCoder = true
(0...n).each do
  colCoder = lineCoder
  (0...n).each do
    print(colCoder ? 'C' : '.')
    colCoder = !colCoder
  end
  puts
  lineCoder = !lineCoder
end

n = gets.to_i
ans = Array.new(n) {Array.new(n) {'.'}}
count = 0
n.times do |i|
    n.times do |j|
        if (i+j)%2==0
            ans[i][j] = 'C'
            count+=1
        end
    end
end
p count
ans.each{|x| puts x.join('')}

n = gets.to_i
puts ((n + 1)/2)**2 + (n/2)**2
n.times do |i|
  n.times do |j|
    print i%2 == j%2 ? 'C' : '.'
  end
  puts
end

n = gets.chomp.to_i

number = 0

(0...n).each do |row|
	(0...n).each do |col|
		if row % 2 == 0
			number += 1 if col % 2 == 0
		else
			number += 1 if col % 2 == 1
		end
	end
end

puts number

(0...n).each do |row|
	(0...n).each do |col|
		if row % 2 == 0
			print 'C' if col % 2 == 0
			print '.' if col % 2 == 1
		else
			print 'C' if col % 2 == 1
			print '.' if col % 2 == 0
		end
	end

	puts ''
end

n = gets.to_i
puts (n*n+1)/2
(1..n).each_with_index do |x,id|
  if x % 2 == 1
    puts "C." * (n/2) + "C" * (n%2)
  else
    puts ".C" * (n/2) + "." * (n%2)
  end
end

n = gets.to_i
dx = Array.new(n).map{|v| v = Array.new(n, 0)}
for i in 0...n do
  for j in 0...n do
    if i % 2 == 0
      dx[i][j] = (j % 2 == 0 ? "C" : ".")
    else
      dx[i][j] = (j % 2 == 0 ? "." : "C")
    end
  end
end
cnt = 0
for i in 0...n do
  for j in 0...n do
    cnt += 1 if dx[i][j] == 'C'
  end
end
puts cnt
for i in 0...n do
  puts dx[i].join()
end

n = gets.to_i
dx = Array.new(n).map{|v| v = Array.new(n, 0)}
for i in 0...n do
  for j in 0...n do
    if i % 2 == 0
      dx[i][j] = (j % 2 == 0 ? "C" : ".")
    else
      dx[i][j] = (j % 2 == 0 ? "." : "C")
    end
  end
end
cnt = 0
for i in 0...n do
  for i in 0...n do
    cnt += 1 if dx[i][j] == 'C'
  end
end
puts cnt
for i in 0...n do
  puts dx[i].join()
end

n = STDIN.gets.to_i
v1 = (n / 2).floor
v2 = (n / 2).ceil
puts v1*v1 + v2*v2
line_coder = true
(0...n).each do
  col_coder = line_coder
  (0...n).each do
    print(col_coder ? 'C' : '.')
    col_coder = !col_coder
  end
  puts
  line_coder = !line_coder
end

n = gets.to_i
n.times do |i|
  if i.even?
    puts ("C." * ((n + 1) / 2)).slice(0..n - 1)
  else
    puts (".C" * ((n + 1) / 2)).slice(0..n - 1)
  end
end

n=gets.to_i
puts n
n.times{|i|
	n.times{|j|
		if i==j then
			print "C"
		else
			print "."
		end
	}
	puts ""
}

n = gets.to_i
ans = Array.new(n) {Array.new(n) {'.'}}
n.times do |i|
    n.times do |j|
        if (i+j)%2==0
            ans[i][j] = 'C'
        end
    end
end
ans.each{|x| puts x.join('')}

n = gets.chomp.to_i

if n == 1
	puts "1"
end

number = 0

(0...n).each do |row|
	(0...n).each do |col|
		if row % 2 == 0
			number += 1 if col % 2 == 0
		else
			number += 1 if col % 2 == 1
		end
	end
end

puts number

(0...n).each do |row|
	(0...n).each do |col|
		if row % 2 == 0
			print 'C' if col % 2 == 0
			print '.' if col % 2 == 1
		else
			print 'C' if col % 2 == 1
			print '.' if col % 2 == 0
		end
	end

	puts ''
end

n = gets.to_i
(1..n).each_with_index do |x,id|
  if x % 2 == 1
    puts "C." * (n/2) + "C" * (n%2)
  else
    puts ".C" * (n/2) + "." * (n%2)
  end
end


a = b = 0
puts "? 0 0"
STDOUT.flush
s = gets.to_i
l = s > 0 ? true : false
f = false
f = true if s == 0
29.downto(0) do |i|
    break if f
    puts "? #{a + (1 << i)} #{b + (1 << i)}"
    STDOUT.flush
    s = gets.to_i
    if s == 0
        f = true
    elsif ((s == -1) && l) || ((s == 1) && !l)
        if s == -1
            a += 1 << i
        else
            b += 1 << i
        end
        puts "? #{a} #{b}"
        STDOUT.flush
        s = gets.to_i
        l = s > 0 ? true : false
        f = true if s == 0
    end
end
29.downto(0) do |i|
    next if a[i] == 1 || b[i] == 1
    puts "? #{a} #{b+(1 << i)}"
    STDOUT.flush
    s = gets.to_i
    if (s == 1)
        a += 1 << i
        b += 1 << i
    end
end
puts "! #{a} #{b}"

ahyp = "X"*30
bhyp = "X"*30
checkedi = 0

puts "? " + "0" + " " + "0"
STDOUT.flush
ans = gets.chomp.to_i

if ans==1
  aisgreater = true
  theyareequal = false
elsif ans==-1
  aisgreater = false
  theyareequal = false
else
  aisgreater = false
  theyareequal = true
end

preva = ""
prevb = ""

61.times do

#  p ahyp
#  p bhyp

  if aisgreater and not theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      end
    elsif res==-1
      puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "0"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end
    #UPDATE PREVSTRINGS, INCREASE ITERVAR

  elsif (not aisgreater) and (not theyareequal)
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    elsif res==-1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i
      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "1"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end

  elsif theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "0"
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "1"
    end
    theyareequal = false
    #DEAL WITH EQUALITY
  end

  preva = ahyp[0..checkedi]
  prevb = bhyp[0..checkedi]
  checkedi = checkedi+1

  if (not ahyp.include?("X"))
    puts "! " + ahyp.to_i(2).to_s + " " + bhyp.to_i(2).to_s
    exit
  end

  #UPDATE PREVSTRINGS, INCREASE ITERVAR
end

a = b = 0
puts "? 0 0"
STDOUT.flush
s = gets.to_i
l = s > 0 ? true : false
f = false
f = true if s == 0
30.downto(0) do |i|
    break if f
    puts "? #{a + (1 << i)} #{b + (1 << i)}"
    STDOUT.flush
    s = gets.to_i
    if s == 0
        f = true
    elsif ((s == -1) && l) || ((s == 1) && !l)
        if s == -1
            a += 1 << i
        else
            b += 1 << i
        end
        puts "? #{a} #{b}"
        STDOUT.flush
        s = gets.to_i
        l = s > 0 ? true : false
        f = true if s == 0
    end
end
30.downto(0) do |i|
    next if a[i] == 1 || b[i] == 1
    puts "? #{a} #{b+(1 << i)}"
    STDOUT.flush
    s = gets.to_i
    if (s == 1)
        a += 1 << i
        b += 1 << i
    end
end
puts "! #{a} #{b}"

a = b = 0
puts "? 0 0"
STDOUT.flush
s = gets.to_i
l = s > 0 ? true : false
f = false
f = true if s == 0
30.downto(0) do |i|
    break if f
    puts "? #{a + (1 << i)} #{b + (1 << i)}"
    STDOUT.flush
    s = gets.to_i
    if s == 0
        f = true
    elsif (s == -1) && l
        a += 1 << i
        puts "? #{a} #{b}"
        STDOUT.flush
        s = gets.to_i
        l = s > 0 ? true : false
        f = true if s == 0
    elsif (s == 1) && !l
        b += 1 << i
    end
end
30.downto(0) do |i|
    next if a[i] == 1 || b[i] == 1
    puts "? #{a} #{b+(1 << i)}"
    STDOUT.flush
    s = gets.to_i
    if (s == 1)
        a += 1 << i
        b += 1 << i
    end
end
puts "! #{a} #{b}"

ahyp = "X"*30
bhyp = "X"*30
checkedi = 0

puts "? " + "0" + " " + "0"
STDOUT.flush
ans = gets.chomp.to_i

if ans==1
  aisgreater = true
  theyareequal = true
elsif ans==-1
  aisgreater = false
  theyareequal = true
else
  aisgreater = false
  theyareequal = true
end

preva = ""
prevb = ""

61.times do

  if aisgreater and not theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      end
    elsif res==-1
      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "0"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end
    #UPDATE PREVSTRINGS, INCREASE ITERVAR

  elsif (not aisgreater) and (not theyareequal)
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    elsif res==-1
      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "1"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end

  elsif theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "0"
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "1"
    end
    theyareequal = true
    #DEAL WITH EQUALITY
  end

  preva = ahyp[0..checkedi]
  preva = bhyp[0..checkedi]
  checkedi = checkedi+1

  if (not ahyp.include?("X"))
    puts "! " + ahyp.to_i(2).to_s + " " + bhyp.to_i(2).to_s
    exit
  end

  #UPDATE PREVSTRINGS, INCREASE ITERVAR
end

ahyp = "X"*30
bhyp = "X"*30
checkedi = 0

puts "? " + "0" + " " + "0"
STDOUT.flush
ans = gets.chomp.to_i

if ans==1
  aisgreater = true
  theyareequal = false
elsif ans==-1
  aisgreater = false
  theyareequal = false
else
  aisgreater = false
  theyareequal = true
end

preva = ""
prevb = ""

61.times do

#  p ahyp
#  p bhyp

  if aisgreater and not theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      end
    elsif res==-1
      puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "0"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end
    #UPDATE PREVSTRINGS, INCREASE ITERVAR

  elsif (not aisgreater) and (not theyareequal)
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    elsif res==-1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i
      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "1"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end

  elsif theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==-1
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "0"
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "1"
    end
    theyareequal = false
    #DEAL WITH EQUALITY
  end

  preva = ahyp[0..checkedi]
  preva = bhyp[0..checkedi]
  checkedi = checkedi+1

  if (not ahyp.include?("X"))
    puts "! " + ahyp.to_i(2).to_s + " " + bhyp.to_i(2).to_s
    exit
  end

  #UPDATE PREVSTRINGS, INCREASE ITERVAR
end

ahyp = "X"*30
bhyp = "X"*30
checkedi = 0

puts "? " + "0" + " " + "0"
STDOUT.flush
ans = gets.chomp.to_i

if ans==1
  aisgreater = true
  theyareequal = false
elsif ans==-1
  aisgreater = false
  theyareequal = false
else
  aisgreater = false
  theyareequal = true
end

preva = ""
prevb = ""

61.times do

#  p ahyp
#  p bhyp

  if aisgreater and not theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      end
    elsif res==-1
      puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "0"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end
    #UPDATE PREVSTRINGS, INCREASE ITERVAR

  elsif (not aisgreater) and (not theyareequal)
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    elsif res==-1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i
      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "1"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end

  elsif theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==-1
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "0"
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "1"
    end
    theyareequal = false
    #DEAL WITH EQUALITY
  end

  preva = ahyp[0..checkedi]
  prevb = bhyp[0..checkedi]
  checkedi = checkedi+1

  if (not ahyp.include?("X"))
    puts "! " + ahyp.to_i(2).to_s + " " + bhyp.to_i(2).to_s
    exit
  end

  #UPDATE PREVSTRINGS, INCREASE ITERVAR
end

ahyp = "X"*30
bhyp = "X"*30
checkedi = 0

puts "? " + "0" + " " + "0"
STDOUT.flush
ans = gets.chomp.to_i

if ans==1
  aisgreater = true
  theyareequal = false
elsif ans==-1
  aisgreater = false
  theyareequal = false
else
  aisgreater = false
  theyareequal = true
end

preva = ""
prevb = ""

61.times do

  p ahyp
  p bhyp

  if aisgreater and not theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      end
    elsif res==-1
      puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "0"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end
    #UPDATE PREVSTRINGS, INCREASE ITERVAR

  elsif (not aisgreater) and (not theyareequal)
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    elsif res==-1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i
      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "1"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end

  elsif theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==-1
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "0"
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "1"
    end
    theyareequal = false
    #DEAL WITH EQUALITY
  end

  preva = ahyp[0..checkedi]
  prevb = bhyp[0..checkedi]
  checkedi = checkedi+1

  if (not ahyp.include?("X"))
    puts "! " + ahyp.to_i(2).to_s + " " + bhyp.to_i(2).to_s
    exit
  end

  #UPDATE PREVSTRINGS, INCREASE ITERVAR
end

ahyp = "X"*30
bhyp = "X"*30
checkedi = 0

puts "? " + "0" + " " + "0"
STDOUT.flush
ans = gets.chomp.to_i

if ans==1
  aisgreater = true
  theyareequal = false
elsif ans==-1
  aisgreater = false
  theyareequal = false
else
  aisgreater = false
  theyareequal = true
end

preva = ""
prevb = ""

61.times do

  p ahyp
  p bhyp

  if aisgreater and not theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = true
        #ALAT > BLAT
      end
    elsif res==-1
      puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "0"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end
    #UPDATE PREVSTRINGS, INCREASE ITERVAR

  elsif (not aisgreater) and (not theyareequal)
    puts "? " + (preva+"0"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"1"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i

      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = true
        #ALAT>BLAT
      elsif newres==-1
        ahyp[checkedi] = "1"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    elsif res==-1
      puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
      STDOUT.flush
      newres = gets.to_i
      if newres ==1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "0"
        aisgreater = false
        #ALAT<BLAT
      elsif newres==-1
        ahyp[checkedi] = "0"
        bhyp[checkedi] = "1"
        aisgreater = false
        #ALAT<BLAT
      end
    else
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "1"
      theyareequal = true
      #DEAL WITH EQUALITY HERE
    end

  elsif theyareequal
    puts "? " + (preva+"1"+"0"*(29-checkedi)).to_i(2).to_s + " " + (prevb+"0"+"0"*(29-checkedi)).to_i(2).to_s
    STDOUT.flush
    res = gets.to_i

    if res==-1
      ahyp[checkedi] = "0"
      bhyp[checkedi] = "0"
    else
      ahyp[checkedi] = "1"
      bhyp[checkedi] = "1"
    end
    theyareequal = false
    #DEAL WITH EQUALITY
  end

  preva = ahyp[0..checkedi]
  preva = bhyp[0..checkedi]
  checkedi = checkedi+1

  if (not ahyp.include?("X"))
    puts "! " + ahyp.to_i(2).to_s + " " + bhyp.to_i(2).to_s
    exit
  end

  #UPDATE PREVSTRINGS, INCREASE ITERVAR
end


n = gets.to_i
n.times do
    x ,y, n = gets.chomp.split(" ").map(&:to_i)
    first = n - y
    kari = first / x
    ans = kari * x + y
    puts ans
end

gets.to_i.times do
	x, y, n = gets.split.map(&:to_i)
	if n % x >= y
		puts n / x * x + y
	else
		puts (n / x - 1) * x + y
	end
end

t = gets.to_i
t.times do
	x,y,n = gets.split.map(&:to_i)
	ans = x * (n/x) + y
	if ans > n
		ans -= x
	end
	puts ans
end

def run
  x, y, n = gets.chomp.split(" ").map(&:to_i)

  l = n % x

  # puts [x, y, n, l].inspect

  if l == y
    puts n
  elsif l > y
    puts n - (l - y)
  else
    puts n - (x - (y - l))
  end
end

def main
  t = gets.chomp.to_i

  t.times do
    run
  end
end

main

gets.to_i.times do
  x, y, n = gets.split.map(&:to_i)
  puts (n - y) / x * x + y
end

def answer(n, x, y)
  return answer(n - n.modulo(x) - 1, x, y) if n.modulo(x) < y

  return n - (n.modulo(x) - y)
end

gets.to_i.times do
  x, y, n = gets.split(' ').map(&:to_i)

  puts answer(n, x, y)
end


n = gets.to_i
ans = 0
(1..n).each do |x|
	ans += 1 / x.to_f
end
puts ans.to_f

s,k=0.0,1.0
a=gets.to_i
while k<=a
	s+=1/k
	k+=1
end
puts (s)


gets.to_i.times{
    a = gets.chomp
    b = gets.chomp
    c = gets.chomp
    x = true
    (0...a.length).each do |i|
        if (a[i] == b[i] && a[i] != c[i] || a[i] != b[i] && b[i] != c[i] && a[i] != c[i])
            x = false
            break
        end
    end
    puts x ? "YES" : "NO"
}

n = Integer gets
for jj in 0...n
s1, s2, s3 = gets.chop!, gets.chop!, gets.chop!
flg = "YES"
for i in 0...s3.size
  if s3[i] != s1[i] && s3[i] != s2[i] then flg = "NO" end
end
puts flg
end

# frozen_string_literal: true

@data = $stdin.read.split

def next_token
  @data.shift
end

def next_int
  next_token.to_i
end

next_int.times do |_i|
  a = next_token
  b = next_token
  c = next_token
  ok = true
  a.size.times do |i|
    next if a[i] == c[i] || b[i] == c[i]

    ok = false
  end
  if ok
    puts 'YES'
  else
    puts 'NO'
  end
end

T = gets.to_i

T.times do
  a = gets.chomp
  b = gets.chomp
  c = gets.chomp
  n = a.size

  success = true

  n.times do |i|
    if a[i] != c[i] && b[i] != c[i]
      success = false
    end
  end

  if success
    puts 'YES'
  else
    puts 'NO'
  end
end

n = gets.to_i
n.times {
  a = gets.chomp
  b = gets.chomp
  c = gets.chomp
  flag = true
  for i in (0..a.length - 1)
    if a[i] != c[i] and b[i] != c[i]
      flag = false
    end
  end
  puts flag ? "YES" : "NO"
}

gets.to_i.times{
    a = gets.chomp
    b = gets.chomp
    c = gets.chomp
    x = true
    (0...a.length).each do |i|
        if !((a[i] == c[i]) ^ (b[i] == c[i]) ^ (a[i] == b[i]))
            x = false
            break
        end
    end
    puts x ? "YES" : "NO"
}

gets.to_i.times{
    a = gets.chomp
    b = gets.chomp
    c = gets.chomp
    x = true
    (0...a.length).each do |i|
        if !((a[i] == c[i]) ^ (b[i] == c[i]))
            x = false
            break
        end
    end
    puts x ? "YES" : "NO"
}


t = gets.chomp.to_i
t.times do
	n, a, b, c, d = gets.chomp.split(" ").map(&:to_i)
	flag = false
	# (n*(a-b)..n*(a+b)).each do |ngo|
	# 	#print ngo.to_s + " "
	# 	if c - d <= ngo && ngo <= c + d then
	# 		flag = true
	# 		break
	# 	end
	# end
	nab1 = n*(a-b)
	nab2 = n*(a+b)
	puts (nab1 <= c-d && c + d <= nab2) || (c-d<=nab1 && nab1<=c+d) || (c-d<=nab2&&nab2<=c+d) ? "Yes" : "No"
end

t = gets.to_i
t.times do
  n, a, b, c, d = gets.split.map(&:to_i)
  ok = true
  if (a - b) * n > (c + d) || (a + b) * n < (c - d)
    ok = false
  end
  puts ok ? "Yes" : "No"
end

def solve n, a, b, c, d
  return "Yes" if n * (a-b) <= c+d && n * (a+b) >= c-d
  "No"
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, a, b, c, d = STDIN.gets.chomp.split.map {|i| i.to_i}
  res = solve n, a, b, c, d
  puts res
end

# Task 1341A
# require 'byebug'

t = gets.chomp.to_i
answers = []
t.times do
    # Reading input
    str = gets.chomp
    n, a, b, c, d = str.split(" ").map{ |n| n.to_i }

    min_weight = a - b
    max_weight = a + b
    min_total = c - d
    max_total = c + d

    if (max_weight * n) < min_total || max_total < (min_weight * n)
        answers << "No"
    else
        answers << "Yes"
    end
end
puts answers

class Range
  def crosses?(x)
    include?(x.first) || include?(x.last) || x.include?(first) || x.include?(last)
  end
end

1.upto(gets.to_i) do
  n, a, b, c, d = gets.split(' ').map(&:to_i)

  puts ((c-d)..(c+d)).crosses?((n*(a-b))..(n*(a+b))) ? 'Yes' : 'No'
end

t = gets.to_i
t.times do
	n, a, b, c, d = gets.strip.split.map(&:to_i)
	min_grains = (a - b) * n
	max_grains = (a + b) * n
	min_pack = c - d
	max_pack = c + d
	if max_grains < min_pack || max_pack < min_grains
		puts "No"
	else
		puts "Yes"
	end
end

gets.to_i.times {
  n, a, b, c, d = gets.split.map { |v| v.to_i }
  min_sum = n * (a - b)
  max_sum = n * (a + b)
  if min_sum > c + d or max_sum < c - d
    puts "No"
  else
    puts "Yes"
  end
}

1.upto(gets.chomp.to_i) do
  n,a,b,c,d = gets.chomp.split.map(&:to_i)
  if (n * (a-b) <= (c+d) && n*(a+b) >= (c-d))
    puts 'Yes'
  else
    puts 'No'
  end
end

t = gets.chomp.to_i
t.times do
	n, a, b, c, d = gets.chomp.split(" ").map(&:to_i)
	flag = false
	(a-b..a+b).each do |ngo|
		if c - d <= n * ngo && n * ngo <= c + d then
			puts "Yes"
			flag = true
			break
		end
	end
	puts "No" if flag == false
end

# Task 1341A
# require 'byebug'

t = gets.chomp.to_i
answers = []
t.times do
    # Reading input
    str = gets.chomp
    n, a, b, c, d = str.split(" ").map{ |n| n.to_i }

    min_weight = a - b
    max_weight = a + b
    min_total = c - d
    max_total = c + d

    if (min_weight * n) >= min_total || ((max_weight * n) <= max_total && (max_weight * n) >= min_total)
        answers << "Yes"
    else
        answers << "No"
    end
end
puts answers

def solve n, a, b, c, d
  tot = [c-d, c+d]
  ((a-b)..(a+b)).each do |i|
    return "Yes" if n * i >= tot[0] && n * i <= tot[1]
    return "Yes" if n * i >= tot[0] && n * i <= tot[1]
  end
  "No"
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, a, b, c, d = STDIN.gets.chomp.split.map {|i| i.to_i}
  res = solve n, a, b, c, d
  puts res
end

def solve n, a, b, c, d
  tot = [c-d, c+d]
  return "Yes" if n * (a-b) >= tot[0] && n * (a-b) <= tot[1]
  return "Yes" if n * (a+b) >= tot[0] && n * (a+b) <= tot[1]
  "No"
end

t = STDIN.gets.chomp.to_i

(1..t).each do |i|
  n, a, b, c, d = STDIN.gets.chomp.split.map {|i| i.to_i}
  res = solve n, a, b, c, d
  puts res
end

t = gets.to_i
t.times do
	n, a, b, c, d = gets.strip.split.map(&:to_i)
	min_grains = (a - b) * n
	max_grains = (a + b) * n
	min_pack = c - d
	max_pack = c + d
	if (min_pack <= min_grains && max_pack >= min_grains) || (min_pack <= max_grains && max_pack >= max_grains)
		puts "Yes"
	else
		puts "No"
	end
end

t = gets.to_i
t.times do
	n, a, b, c, d = gets.strip.split.map(&:to_i)
	min_grains = (a - b) * n
	max_grains = (a + b) * n
	min_pack = c - d
	max_pack = c + d
	if (min_pack <= min_grains && min_grains <= max_pack) || (min_pack <= max_grains && max_grains <= max_pack)
		puts "Yes"
	else
		puts "No"
	end
end


n = gets.to_i
n.times do
  c = false
  ip = gets.strip.split(":")
  if ip[0] == "" then ip = ip.drop(1) end
  l = ip.count
  for i in 0...l
    if ip[i] == ""
      if i > 0 then print ":" end
      print "0000"
      (8 - l).times do
        print ":0000"
      end
      c = true
    else
      if i > 0 then print ":" end
      (4 - ip[i].length).times do print "0" end
      print ip[i]
    end
  end
  if l != 8 && !c
    if l > 0 then print ":" end
    print "0000"
    (7 - l).times do
      print ":0000"
    end
  end
  puts ""
end

gets.to_i.times do
  bb = gets.strip.gsub('::', ':zero:').split(':')
  seq_len = 8 - bb.size + 1
  blocks = []
  bb.each do |b|
    if b == 'zero'
      seq_len.times{ blocks << '0000' }
    else
      blocks << '0' * (4 - b.size) + b
    end
  end

  puts blocks.join(':')
end

n=Integer(gets.chomp)

n.times do
s=gets.chomp
a=s.split '::'
if a[0]!=nil
b=a[0].split ':'
else
b=[]
end
if a[1]!=nil
c=a[1].split ':'
else
c=[]
end

a=b+Array.new(8-(b.size+c.size),"0000")+c
a.map!{|i| "0"*(4-i.size)+i}

(a.size-1).times do |i|
print a[i]+':'
end
print a[-1]+"\n"

end

gets.to_i.times {
  short = gets.strip.gsub('::', ':zero:').split(':')
  seq_len = 8 - short.size + 1
  blocks = []
  short.each { |b|
    if b == 'zero'
      seq_len.times{ blocks << '0000' }
    else
      blocks << '0' * (4 - b.size) + b
    end
  }

  puts blocks.join(':')
}

#require 'colorize'

def recoveryPart(part)
  zones = part.split(':')
  fullPart = String.new

  zones.each { |zone|
    fullPart += ('0' * (4 - zone.length)) + zone + ':'

  }

  fullPart[0..-2]
end

def recoveryIpv6(shortIpv6)

  part = shortIpv6.split('::')

  case part.length
    when 0
      result = ('0000:'*8)[0..-2]
    when 1
      if (shortIpv6[shortIpv6.length-2..shortIpv6.length] == '::')
        result = recoveryPart(part[0]) + ':' + ('0000:' * (8 - part[0].split(':').length))
      else
        result = recoveryPart(shortIpv6)
      end
    when 2
      result = recoveryPart(part[0]) + ':' + ('0000:' * (8 - (part[0].split(':').length + part[1].split(':').length)))  + recoveryPart(part[1])
  end

  if (result[0..0] == ':')
    result = result[1..result.length]
  end

  if (result[result.length-1..result.length] == ':')
    result = result[0..result.length-2]
  end
  result

end

count = gets.chomp.to_i;

count.times do
  puts recoveryIpv6(gets.chomp)
end

#
# TEST
#

#if recoveryIpv6('a56f:d3:0:0124:01:f19a:1000:00') == 'a56f:00d3:0000:0124:0001:f19a:1000:0000'
#  puts 'OK'.green
#else
#  puts 'FAIL'.red
#end
#
#if recoveryIpv6('a56f:00d3:0000:0124:0001::') == 'a56f:00d3:0000:0124:0001:0000:0000:0000'
#  puts 'OK'.green
#else
#  puts 'FAIL'.red
#end
#
#if recoveryIpv6('::a56f:00d3:0000:0124:0001') == '0000:0000:0000:a56f:00d3:0000:0124:0001'
#  puts 'OK'.green
#else
#  puts 'FAIL'.red
#end
#
#if recoveryIpv6('a56f::0124:0001:0000:1234:0ff0') == 'a56f:0000:0000:0124:0001:0000:1234:0ff0'
#  puts 'OK'.green
#else
#  puts 'FAIL'.red
#end
#
#if recoveryIpv6('a56f:0000::0000:0001:0000:1234:0ff0') == 'a56f:0000:0000:0000:0001:0000:1234:0ff0'
#  puts 'OK'.green
#else
#  puts 'FAIL'.red
#end
#
#if recoveryIpv6('::') == '0000:0000:0000:0000:0000:0000:0000:0000'
#  puts 'OK'.green
#else
#  puts 'FAIL'.red
#end
#
#if recoveryIpv6('0ea::4d:f4:6:0') == '00ea:0000:0000:0000:004d:00f4:0006:0000'
#  puts 'OK'.green
#else
#  puts 'FAIL'.red
#end

n = gets.to_i
n.times do
  c = false
  ip = gets.strip.split(":")
  l = ip.count
  for i in 0...l
    if ip[i] == ""
      if i > 0 then print ":" end
      print "0000"
      (8 - l).times do
        print ":0000"
      end
      c = true
    else
      if i > 0 then print ":" end
      (4 - ip[i].length).times do print "0" end
      print ip[i]
    end
  end
  if l != 8 && !c
    if l > 0 then print ":" end
    print "0000"
    (7 - l).times do
      print ":0000"
    end
  end
  puts ""
end

n = gets.to_i
n.times do
  c = false
  ip = gets.strip.split(":")
  l = ip.count
  for i in 0...l
    if ip[i] == ""
      if i > 0 then print ":" end
      print "0000"
      (8 - l).times do
        print ":0000"
      end
      c = true
    else
      if i > 0 then print ":" end
      (4 - ip[i].length).times do print "0" end
      print ip[i]
    end
  end
  if !c
    if l > 0 then print ":" end
    print "0000"
    (7 - l).times do
      print ":0000"
    end
  end
  puts ""
end

#!ruby -plr ipaddr
#$_=IPAddr.new($_).to_string
$_=2