local mfl, mce = math.floor, math.ceil local function query(str) io.write(str .. "\n") io.flush() local ret = io.read("*l") return ret end local n, m = io.read("*n", "*n", "*l") local t = {} for i = 1, 4 * n * n do t[i] = false end local map = {} -- 0:unknown, 1:black, 2:white for i = 1, n * n do map[i] = 0 end map[1], map[n * n] = 1, 1 local function checkmap(row, col) local mapidx = (row - 1) * n + col if map[mapidx] == 0 then local ans = query(row .. " " .. col) if ans == "Black" then map[mapidx] = 1 else map[mapidx] = 2 end end end local pos = 1 while true do -- print(pos) if t[pos] then io.write("No\n") io.flush() os.exit() end t[pos] = true local way = mce(pos / n / n) local mapidx = pos - (way - 1) * n * n if mapidx == n * n then io.write("Yes\n") io.flush() os.exit() end local row = mce(mapidx / n) local col = mapidx - (row - 1) * n if way == 1 then -- up if 1 < row then checkmap(row - 1, col) end if 1 < row and map[mapidx - n] == 1 then pos = 3 * n * n + (row - 2) * n + col else pos = 1 * n * n + (row - 1) * n + col end elseif way == 2 then -- right if col < n then checkmap(row, col + 1) end if col < n and map[mapidx + 1] == 1 then pos = 0 * n * n + (row - 1) * n + col + 1 else pos = 2 * n * n + (row - 1) * n + col end elseif way == 3 then -- down if row < n then checkmap(row + 1, col) end if row < n and map[mapidx + n] == 1 then pos = 1 * n * n + row * n + col else pos = 3 * n * n + (row - 1) * n + col end else -- left if 1 < col then checkmap(row, col - 1) end if 1 < col and map[mapidx - 1] == 1 then pos = 2 * n * n + (row - 1) * n + col - 1 else pos = 0 * n * n + (row - 1) * n + col end end end