N, M = gets.split.map(&:to_i) def query(a, b) STDOUT.puts("%d %d" % [a, b]) gets.chomp end G = Array.new(N) { Array.new(N, 0) } visited = Array.new(N) { Array.new(N, false) } DY = [-1, 0, 1, 0] DX = [0, 1, 0, -1] def dfs(y, x, visited) visited[y][x] = true if y == N - 1 && x == N - 1 puts 'Yes' exit end 4.times do |i| ny = y + DY[i] nx = x + DX[i] next if ny < 0 || nx < 0 || N <= ny || N <= nx next if visited[ny][nx] res = query(ny + 1, nx + 1) if res == 'Black' dfs(ny, nx, visited) end end end dfs(0, 0, visited) puts 'No'