#P1543D1. RPD and Rap Sheet (Easy Version)

    ID: 544 Type: RemoteJudge 5000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>bitmasksconstructive algorithmsinteractivemath*1700

RPD and Rap Sheet (Easy Version)

No submission language available for this problem.

Description

This is the easy version of the problem. The only difference is that here k=2k=2. You can make hacks only if both the versions of the problem are solved.

This is an interactive problem.

Every decimal number has a base kk equivalent. The individual digits of a base kk number are called kk-its. Let's define the kk-itwise XOR of two kk-its aa and bb as (a+b)modk(a + b)\bmod k.

The kk-itwise XOR of two base kk numbers is equal to the new number formed by taking the kk-itwise XOR of their corresponding kk-its. The kk-itwise XOR of two decimal numbers aa and bb is denoted by akba\oplus_{k} b and is equal to the decimal representation of the kk-itwise XOR of the base kk representations of aa and bb. All further numbers used in the statement below are in decimal unless specified. When k=2k = 2 (it is always true in this version), the kk-itwise XOR is the same as the bitwise XOR.

You have hacked the criminal database of Rockport Police Department (RPD), also known as the Rap Sheet. But in order to access it, you require a password. You don't know it, but you are quite sure that it lies between 00 and n1n-1 inclusive. So, you have decided to guess it. Luckily, you can try at most nn times without being blocked by the system. But the system is adaptive. Each time you make an incorrect guess, it changes the password. Specifically, if the password before the guess was xx, and you guess a different number yy, then the system changes the password to a number zz such that xkz=yx\oplus_{k} z=y. Guess the password and break into the system.

The first line of input contains a single integer tt (1t100001\leq t\leq 10\,000) denoting the number of test cases. tt test cases follow.

The first line of each test case contains two integers nn (1n21051\leq n\leq 2\cdot 10^5) and kk (k=2k=2).

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5.

Interaction

For each test case, first read two integers nn and kk. Then you may ask up to nn queries.

For each query, print a single integer yy (0y21070\leq y\leq 2\cdot 10^7). Let the current password be xx. After that, read an integer rr.

If x=yx=y, you will read r=1r=1 and the test case is solved. You must then continue solving the remaining test cases.

Else, you will read r=0r=0. At this moment the password is changed to a number zz such that xkz=yx\oplus_{k} z=y.

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

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 you ask an invalid query or exceed nn queries, you will read r=1r=-1 and you will receive the Wrong Answer verdict. Make sure to exit immediately to avoid unexpected verdicts.

Note that the interactor is adaptive. That is, the original password is not fixed in the beginning and may depend on your queries. But it is guaranteed that at any moment there is at least one initial password such that all the answers to the queries are consistent.

Hacks:

To use hacks, use the following format of tests:

The first line should contain a single integer tt (1t100001\leq t\leq 10\,000) — the number of test cases.

The first and only line of each test case should contain two integers nn (1n21051\leq n\leq 2\cdot 10^5) and kk (k=2k=2) denoting the number of queries and the base respectively. The optimal original password is automatically decided by the adaptive interactor.

You must ensure that the sum of nn over all test cases does not exceed 21052\cdot 10^5.

Input

The first line of input contains a single integer tt (1t100001\leq t\leq 10\,000) denoting the number of test cases. tt test cases follow.

The first line of each test case contains two integers nn (1n21051\leq n\leq 2\cdot 10^5) and kk (k=2k=2).

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5.

Samples

Sample Input 1

1
5 2

0

0

1

Sample Output 1

3

4

5

Note

In the example test case, the hidden password is 22.

The first query is 33. It is not equal to the current password. So, 00 is returned, and the password is changed to 11 since 221=32\oplus_2 1=3.

The second query is 44. It is not equal to the current password. So, 00 is returned, and the password is changed to 55 since 125=41\oplus_2 5=4.

The third query is 55. It is equal to the current password. So, 11 is returned, and the job is done.

Note that this initial password is taken just for the sake of explanation. When you submit, the interactor might behave differently because it is adaptive.