Assiut Chess
Contest: Codeforces Round 737 (Div. 2)
Difficulty rating: 2800
Tags: brute force, constructive algorithms, interactive

This is an interactive problem.

ICPC Assiut Community decided to hold a unique chess contest, and you were chosen to control a queen and hunt down the hidden king, while a member of ICPC Assiut Community controls this king.

You compete on an $$$8\times8$$$ chessboard, the rows are numerated from top to bottom, and the columns are numerated left to right, and the cell in row $$$x$$$ and column $$$y$$$ is denoted as $$$(x, y)$$$.

In one turn you can move the queen to any of the squares on the same horizontal line, vertical line, or any of the diagonals. For example, if the queen was on square ($$$4$$$, $$$5$$$), you can move to ($$$q_1$$$, $$$5$$$), ($$$4$$$, $$$q_1$$$), ($$$q_1$$$, $$$9-q_1$$$), or ($$$q_2$$$, $$$q_2+1$$$) where ($$$1 \le q_1 \le 8$$$, $$$q_1 \ne 4$$$, $$$1 \le q_2 \le 7$$$, $$$q_2 \ne 4$$$). Note that the queen cannot stay on its current cell.

In one turn, the king can move "Right", "Left", "Up", "Down", "Down-Right", "Down-Left", "Up-Left", or "Up-Right" such that he doesn't get out of the board. The king cannot move into a cell that is on the same row, column or diagonal with the queen (including the position of the queen itself). For example, if the king was on square ($$$4$$$, $$$5$$$), he can move to ($$$4+k_1$$$, $$$5+k_2$$$) where ($$$-1 \le k_1,k_2 \le 1$$$, $$$(k_1, k_2) \ne (0, 0)$$$).

At the start of the game, you should place the queen at any location on the board, and this is done once per game. After that the king is secretly placed at any cell different from the queen's location. You do not know the position of the king. Then, the king and the queen take turns with the king moving first. The king moves to one of the possible directions ("Right", "Down", "Up-Left", etc.), and you are only given the direction it moves to. After that, you should move your queen by declaring the square to which your queen will move. The game follows like this until you win the game or run out of moves.

You win if the king has no valid moves. You lose if after $$$130$$$ moves of the queen the king still has valid moves.

Input format:
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 60$$$) — the number of test cases.

Interaction format:
In each test case, you should print the queen's starting cell immediately. If you placed the queen at the king's cell, you will win immediately.

After that, you may make at most $$$130$$$ moves. Each move is made in the format $$$x$$$ $$$y$$$, where $$$x$$$ and $$$y$$$ are two integers ($$$1 \leq x,y \leq 8$$$) that denote the new row and column of the queen respectively. Your move should be a valid queen move.

After the initial queen placement and after each move you will receive a string $$$s$$$ that represents the direction of the king's move. It will be one of the following: "Right", "Left", "Up", "Down", "Down-Right", "Down-Left", "Up-Left", "Up-Right", or "Done" if you win the game. You should consider "Done" as the end of each test case.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.

If at any point you make an invalid query or try to make more than $$$130$$$ queries for each test case, the game will terminate immediately and you will receive a Wrong Answer verdict.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the example, the hidden king was at $$$(8, 8)$$$ at the start. The game follows like this:

Example input:
1
Left
Right
Done

Example output:
7 5
7 6
7 7

Editorial:
This is one of many possible solutions. We need to force the king to move into one of the four corners (bottom right or bottom left corner in this solution) to ensure that the king will be trapped (cannot move anymore).
Place the queen on the top row. After the king makes $$$1$$$ move, he should be below the queen's row.
Suppose the queen is on the row $$$x$$$ with the king below it (row $$$x$$$ $$$+$$$ $$$i$$$ where $$$i$$$ > $$$0$$$).
If $$$i$$$ $$$=$$$ $$$1$$$, we cannot move down to the next row as the king may move up and we will not be able to trap it. Otherwise, we can move down by one unit.
To ensure that the king is not on the next row, scan the current row, $$$x$$$, by moving the queen from the leftmost column to the rightmost column one square at a time. Therefore, you can move the queen as follows:
1. During the scan, if you have visited all $$$8$$$ squares of the current row and the king never made a vertical or diagonal move, it means that $$$i \ge 2$$$ and you can go down by one row. It is now guaranteed that the king is still below the queen.
2. If the king were on row $$$x$$$ $$$+$$$ $$$1$$$, he would have been forced to move $$$1$$$ square down at some point. If he ever goes down, move the queen down by one row.
3. If the king moves up, start scanning the row again. This can only happen a limited number of times without the king moving into a check.
In total, the queen needs to apply step $$$2$$$ up to $$$8$$$ times. At each row, step $$$1$$$ needs to be applied, so it takes $$$8$$$ moves. Step $$$1$$$ also needs to be applied every time step $$$3$$$ is applied, which can happen at most $$$8$$$ times. In total, that is $$$8$$$ $$$\cdot$$$ $$$(8$$$ $$$+$$$ $$$8)$$$ $$$=$$$ $$$128$$$ moves.