def send_query(str) STDOUT.puts(str) STDOUT.flush res = gets.chomp if res == "Merry Christmas!" -1 else res.to_i end end v = gets.to_i v.times do res = send_query("F") exit if res == -1 end send_query("R") loop do res = send_query("L") if res > 0 f = send_query("F") if f < 0 exit end else f = send_query("R") if f > 0 r = send_query("F") if r < 0 exit end else send_query("R") end end end