311104: CF1934D2. XOR Break — Game Version

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D2. XOR Break — Game Versiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

This is an interactive problem.

This is the game version of the problem. Note that the solution of this problem may or may not share ideas with the solution of the solo version. You can solve and get points for both versions independently.

Alice and Bob are playing a game. The game starts with a positive integer $n$, with players taking turns. On each turn of the game, the following sequence of events takes place:

  • The player having the integer $p$ breaks it into two integers $p_{1}$ and $p_{2}$, where $0 \lt p_{1} \lt p$, $0 \lt p_{2} \lt p$ and $p_{1} \oplus p_{2} = p$.
  • If no such $p_{1}$, $p_{2}$ exist, the player loses.
  • Otherwise, the opponent does either select the integer $p_{1}$ or $p_{2}$.
  • The game continues with the selected integer. The opponent will try to break it.

As Alice, your goal is to win. You can execute a maximum of $63$ break operations. You have the choice to play first or second. The system will act for Bob.

Here $\oplus$ denotes the bitwise XOR operation.

Input

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.

The only line of each test case contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the number the game starts with.

Interaction

For each test case, the interaction begins by reading the integer $n$.

After reading $n$, print a single line containing either "first" or "second", denoting what you want to play as (as first or second correspondingly).

On Alice's turn, you are required to print two positive integers, $p_{1}$ and $p_{2}$ such that $0 \lt p_{1} \lt p$, $0 \lt p_{2} \lt p$ and $p_{1} \oplus p_{2} = p$. Here, $p$ equals one of the two integers printed by Bob in the previous turn. If no turn has occurred previously, $p$ is equal to $n$. If Alice cannot perform a break operation, print "0 0" to receive a Wrong answer verdict.

On Bob's turn, you should read two integers, $p_{1}$ and $p_{2}$ such that $0 \lt p_{1} \lt p$, $0 \lt p_{2} \lt p$ and $p_{1} \oplus p_{2} = p$. Here, $p$ equals one of the two integers printed by Alice in the previous turn. If no turn has occurred previously, $p$ is equal to $n$. If Bob cannot perform a break operation $p_{1} = 0$ and $p_2 = 0$ in which case you should proceed to the next test case.

If any break operation performed by Alice is invalid, the interactor prints "-1 -1" and your code should promptly exit to receive a wrong answer verdict.

If Alice performs $63$ turns and Bob can still execute a break operation on the current integers, the interactor prints "-1 -1", and your code should promptly exit to receive a wrong answer verdict.

After printing a query, do not forget to output the 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 the documentation for other languages.

In this problem, hacks are disabled.

ExampleInput
4
1

0 0
3


0 0
13


3 4

0 0
777777770001


0 0
Output


second


first
2 1


first
10 7

1 2


first
777777770000 1
Note

Explanation for the interaction.

Interactor / BobAliceExplanation
4$t$
1$n$ for the first test case
secondAlice chooses to go second
0 0Bob says he cannot break $p = 1$
3$n$ for the second test case
firstAlice chooses to go first
1 2Alice breaks $p = 3$ into $p_1 = 1$ and $p_2 = 2$
0 0Bob says he cannot break $p = 1$ or $p = 2$
13$n$ for the third test case
firstAlice chooses to go first
10 7Alice breaks $p = 13$ into $p_1 = 10$ and $p_2 = 7$
3 4Bob breaks $p = 7$ into $p_1 = 3$ and $p_2 = 4$
1 2Alice breaks $p = 3$ into $p_1 = 1$ and $p_2 = 2$
0 0Bob says he cannot break $p = 1$ or $p = 2$
777777770001$n$ for the fourth test case
firstAlice chooses to go first
777777770000 1Alice breaks $p = 777\,777\,770\,001$ into $p_1 = 777\,777\,770\,000$ and $p_2 = 1$
0 0Bob says he cannot perform break operation.

This table is for explanation only and does not reflect the actual behavior of the interactor.

Note that in the last test case Bob could choose $p_1$ and perform a break operation but he gave up.

Output

题目大意:
这是一个交互式问题,是“XOR Break”问题的游戏版本。Alice和Bob在游戏中轮流进行操作,游戏开始时有一个正整数n。每一轮游戏中,当前玩家需要将整数p拆分为两个整数p1和p2,满足0
输入输出数据格式:
输入:
- 第一行包含一个整数t(1≤t≤1000),表示测试用例的数量。
- 每个测试用例包含一个整数n(1≤n≤10^18),表示游戏的起始数字。

交互过程:
- 对于每个测试用例,首先读取整数n。
- 然后打印一行,包含“first”或“second”,表示你想作为先手还是后手。
- 在Alice的回合,需要打印两个正整数p1和p2,满足0 - 在Bob的回合,需要读取两个整数p1和p2,满足0
如果Alice的任何拆分操作无效,交互器将打印“-1 -1”,你的代码应立即退出以获得错误答案。如果Alice进行了63次操作,而Bob仍然可以对当前整数执行拆分操作,则交互器将打印“-1 -1”,你的代码应立即退出以获得错误答案。

在打印查询后,不要忘记输出换行符并刷新输出,否则你将得到“Idleness limit exceeded”。在C++中可以使用fflush(stdout)或cout.flush(),在Java中可以使用System.out.flush(),在Pascal中可以使用flush(output),在Python中可以使用stdout.flush()。

注意:在这个问题中,攻击是禁用的。题目大意: 这是一个交互式问题,是“XOR Break”问题的游戏版本。Alice和Bob在游戏中轮流进行操作,游戏开始时有一个正整数n。每一轮游戏中,当前玩家需要将整数p拆分为两个整数p1和p2,满足0

加入题单

上一题 下一题 算法标签: