410614: GYM104065 J Middle Race

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Middle Racetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

This is an interactive problem.

Middle Race is a board game featured in the game show "The Genius". In Middle Race, several players will run a race on the board, avoiding finishing the first or the last. In this problem, you are required to play a simplified version of this game versus BoBo and oBoB.

This game consists of $$$n$$$ rounds. Before the game starts, three integer parameters $$$A$$$, $$$B$$$, and $$$C$$$ will be presented. Three items with values $$$A$$$, $$$B$$$, and $$$C$$$, respectively, will be given in each round. You, BoBo, and oBoB will choose to take one item among the remaining ones in order.

Let $$$X, Y, Z$$$ be the total values of the items you, BoBo, and oBoB take in all rounds, respectively. You win the game if and only if $$$\min(Y,Z) \le X \le \max(Y,Z)$$$.

To show that you are smarter than BoBo, please win the game or determine that there exists no winning strategy, i.e., you have no chance of winning if BoBo and oBoB are taking optimal moves.

Interaction

Each test run contains multiple test cases. You should first read a line with an integer $$$T$$$ $$$(1 \le T \le 10^5)$$$, representing the number of test cases.

For each test case, you begin the interaction by reading integers $$$n, A, B, C$$$ ($$$1 \le n, A, B, C \le 10^5$$$) in a line, denoting the number of rounds and parameters of the game.

If no winning strategy exists under the given input, output $$$-1$$$ in a separate line, then continue processing the next test case, if any.

Otherwise, you should complete $$$n$$$ rounds of the game. In each round, you should first output an integer $$$x \in \{A, B, C\}$$$ in one line, indicating that you are going to take an item with value $$$x$$$ in this round. If you perform an invalid move, you will read -1 -1 in the next separate line, and you must terminate your program immediately to receive the correct verdict. Otherwise, two integers $$$y,z$$$ will be given in the next line, indicating that BoBo takes an item with value $$$y$$$ and oBoB takes the one with value $$$z$$$ in this round. After completing all $$$n$$$ rounds, please continue processing the next test case, if any.

It is guaranteed that the sum of $$$n$$$ over all test cases in a single run will not exceed $$$10^5$$$.

After printing an integer, do not forget to output end of line and flush the output. Otherwise, you may not get the correct verdict. To flush the output, use:

  • fflush(stdout) or cout.flush() in C/C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python.
ExampleInput
2
1 1 1 1

1 1
2 1 3 2

1 3

1 3
Output


1


2

2
Note

Empty lines are for better understanding, and you must not output empty lines in your program.

加入题单

算法标签: