This is an interactive problem.

John and his imaginary friend play a game. There are $n$ lamps arranged in a circle. Lamps are numbered $1$ through $n$ in clockwise order, that is, lamps $i$ and $i + 1$ are adjacent for any $i = 1, \ldots, n - 1$, and also lamps $n$ and $1$ are adjacent. Initially all lamps are turned off.

John and his friend take turns, with John moving first. On his turn John can choose to terminate the game, or to make a move. To make a move, John can choose any positive number $k$ and turn any $k$ lamps of his choosing on. In response to this move, John's friend will choose $k$ consecutive lamps and turn all of them off (the lamps in the range that were off before this move stay off). Note that the value of $k$ is the same as John's number on his last move. For example, if $n = 5$ and John have just turned three lamps on, John's friend may choose to turn off lamps $1, 2, 3$, or $2, 3, 4$, or $3, 4, 5$, or $4, 5, 1$, or $5, 1, 2$.

After this, John may choose to terminate or move again, and so on. However, John can not make more than $10^4$ moves.

John wants to maximize the number of lamps turned on at the end of the game, while his friend wants to minimize this number. Your task is to provide a strategy for John to achieve optimal result. Your program will play interactively for John against the jury's interactor program playing for John's friend.

Suppose there are $n$ lamps in the game. Let $R(n)$ be the number of turned on lamps at the end of the game if both players act optimally. Your program has to terminate the game with at least $R(n)$ turned on lamps within $10^4$ moves. Refer to Interaction section below for interaction details.

Interaction

Initially your program will be fed a single integer $n$ ($1 \leq n \leq 1000$) — the number of lamps in the game. Then the interactor will wait for your actions.

To make a move, print a line starting with an integer $k$ ($1 \leq k \leq n$), followed by $k$ distinct integers $l_1, \ldots, l_k$ ($1 \leq l_i \leq n$) — indices of lamps you want to turn on. The indices may be printed in any order. It is allowed to try to turn on a lamp that is already on (although this will have no effect).

If your move was invalid for any reason, or if you have made more than $10^4$ moves, the interactor will reply with a line containing a single integer $-1$. Otherwise, the reply will be a line containing a single integer $x$ ($1 \leq x \leq n)$, meaning that the response was to turn off $k$ consecutive lamps starting from $x$ in clockwise order.

To terminate the game instead of making a move, print a line containing a single integer $0$. The test will be passed if at this point there are at least $R(n)$ lamps turned on (note that neither $R(n)$, nor the verdict received are not communicated to your program in any way). This action does not count towards the number of moves (that is, it is legal to terminate the game after exactly $10^4$ moves).

To receive the correct verdict, your program should terminate immediately after printing $0$, or after receiving $-1$ as a response.

Don't forget to flush your output after every action.

Examples

Input

```
3
```

Output

```
0
```

Input

```
4

1
```

Output

```
2 1 3

0
```

Note

When $n = 3$, any John's move can be reversed, thus $R(3) = 0$, and terminating the game immediately is correct.

$R(4) = 1$, and one strategy to achieve this result is shown in the second sample case.

Blank lines in sample interactions are for clarity and should not be printed.

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {

    }
}

[[noreturn]] static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static void sendMinusOne() {
    cout << -1 << "\n";
    cout.flush();
}

static int compute_R(int n) {
    int best = 0;
    for (int k = 1; k <= n; k++) {
        int ceil_div = (n + k - 1) / k;
        best = max(best, n - ceil_div - k + 1);
    }
    return best;
}

static int choose_adversarial_segment_start(const vector<char>& on, int n, int k) {

    int best_x = 1;
    int best_cnt = -1;

    for (int x = 1; x <= n; x++) {
        int cnt = 0;
        for (int t = 0; t < k; t++) {
            int idx = ((x - 1 + t) % n) + 1;
            cnt += (on[idx] != 0);
        }
        if (cnt > best_cnt) {
            best_cnt = cnt;
            best_x = x;
        }
    }
    return best_x;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    registerInteraction(argc, argv);
    atexit(log_metrics);

#if defined(SIGPIPE)
    signal(SIGPIPE, SIG_IGN);
#endif

    const int n = inf.readInt(1, 1000, "n");
    if (!inf.seekEof()) finish(_fail, "unexpected extra tokens in hidden input");

    query_limit = 10000;
    const long long hard_cap = max(200000LL, 10LL * max(1LL, query_limit));

    log_metrics();

    cout << n << "\n";
    cout.flush();

    vector<char> on(n + 1, 0);
    long long moves = 0;

    while (true) {
        long long k_ll;
        if (!(cin >> k_ll)) finish(_pe, "unexpected EOF from contestant");

        if (k_ll == 0) {
            int on_cnt = 0;
            for (int i = 1; i <= n; i++) on_cnt += (on[i] != 0);
            int R = compute_R(n);
            if (on_cnt >= R) finish(_ok, "OK");
            finish(_wa, "terminated with insufficient lamps on");
        }

        if (moves >= query_limit) {
            sendMinusOne();
            finish(_wa, "too many moves");
        }

        if (!(1 <= k_ll && k_ll <= n)) {
            sendMinusOne();
            finish(_wa, "invalid k");
        }
        int k = (int)k_ll;

        vector<int> idxs;
        idxs.reserve(k);
        vector<char> seen(n + 1, 0);
        for (int i = 0; i < k; i++) {
            long long v_ll;
            if (!(cin >> v_ll)) {
                sendMinusOne();
                finish(_pe, "malformed move payload");
            }
            if (!(1 <= v_ll && v_ll <= n)) {
                sendMinusOne();
                finish(_wa, "lamp index out of range");
            }
            int v = (int)v_ll;
            if (seen[v]) {
                sendMinusOne();
                finish(_wa, "duplicate lamp index in move");
            }
            seen[v] = 1;
            idxs.push_back(v);
        }

        for (int v : idxs) on[v] = 1;

        int x = choose_adversarial_segment_start(on, n, k);
        for (int t = 0; t < k; t++) {
            int idx = ((x - 1 + t) % n) + 1;
            on[idx] = 0;
        }

        moves++;
        queries = moves;
        if (queries > hard_cap) finish(_pe, "hard cap exceeded");

        cout << x << "\n";
        cout.flush();
    }
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    const long long seed = (argc >= 2) ? atoll(argv[1]) : 1;

    int n = 1000;
    if (seed == 1) n = 1;
    else if (seed == 2) n = 2;
    else if (seed == 3) n = 3;
    else if (seed <= 10) n = 10 * (int)seed;
    else n = 1000;
    n = max(1, min(1000, n));

    cout << n << "\n";
    return 0;
}


Erik and his grandpa often go to the forest to pick blueberries. Grandpa always finds the most berries, and even though it is not a competition, Erik has had enough of this. He has observed that grandpa uses a simple greedy strategy to pick as many berries as possible. With this information, Erik will try to finally pick at least as many berries as grandpa.

![](images/45f070646c0f1e55c0c88f578193eb379418410163659f5e4986c1ac6796b012.jpg)
Picture by MAKY.OREL, public domain

The blueberry shrubs can be represented as a string $s =$ $s _ { 1 } s _ { 2 } \ldots s _ { N }$ of length $N = 1 0 ^ { 5 }$ , consisting of characters . and b. If $s _ { i } = \mathrm { b }$ , then there is a berry at position $i$ , otherwise there is no berry there. There will be exactly $N / 2$ berries to start with, and they are distributed uniformly at random.

The berry picking takes place in turns. In one move, a person can choose a position $i$ $( 1 \leq i \leq N - 3 )$ , and pick all the berries at positions $i , i + 1 , i + 2$ , and $i + 3$ . Grandpa makes the first move, then Erik makes a move, then grandpa, and so on. Grandpa will always greedily make a move that picks as many berries as possible. Among all such moves, he will pick one uniformly at random.

You are given the string $s$ , and your task is to write a program that decides what moves Erik should make in order to pick at least as many berries as grandpa.

# Interaction

The first line of input contains the number $N$ , the length of the string $s$ . This number will always be equal to $1 0 ^ { 5 }$ , except for in the sample. Your program does not have to solve the sample to get accepted.

The second line contains the string $s$ of length $N$ . This string has exactly $N / 2$ characters b, and their positions are generated uniformly at random.

Then, your program should start interacting with the grader. When it is grandpa’s turn, you should read a single integer $i$ $1 \leq i \leq N - 3 )$ , meaning that grandpa picks the berries at positions $i , i + 1 , i + 2$ , and $i + 3$ . When it is your turn, you should instead print a number $i$ meaning that you pick the berries at positions $i , i + 1 , i + 2$ , and $i + 3$ .

If it is your turn and there are no more berries, your program should terminate without printing anything more. If it is grandpa’s turn and there are no berries, then the grader will not make any more moves, and your program should also terminate without printing anything more. If you picked at least as many berries as grandpa, you pass the test case.

Each turn, grandpa greedily makes a move that picks as many berries as possible, and among all such moves, he chooses one uniformly at random.

The strings $s$ were generated beforehand, so they are the same across different submissions. However, grandpa’s behaviour is randomized every submission, so it is possible to get different results if you submit the same code twice.

There will be 100 test cases. It is guaranteed that there exists a solution that passes this many cases with very high probability.

# Example

In the sample, Erik and grandpa get 5 berries each, which means that Erik achieved his goal. At the very start of the game, the maximum number of berries possible to pick in one move is 3. There are a 4 possible choices of $i$ that gets 3 berries: 1, 2, 3 and 6. Grandpa chooses one of these uniformly at random which ends up being $i = 2$ . After that, Erik chooses $i = 6$ which gives him three berries as well. In the last two turns, both grandpa and Erik pick two berries.

Read Sample Interaction 1

20 .bbb.b.bb...b.b...bb

2

6

13	17

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static int N;
static string s;
static int berries_remaining = 0;
static long long erik_score = 0;
static long long grandpa_score = 0;

static vector<int> val;
static vector<int> pos_in_list;
static vector<int> lists[5];

static unsigned long long seed = 84421337ULL;
unsigned long long next_rand() {
    seed = seed * 6364136223846793005ULL + 1442695040888963407ULL;
    return seed;
}

int get_rand_index(int range) {
    if (range <= 0) return 0;
    return (int)(next_rand() % range);
}

static void log_metrics() {
    try {

        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {}
}

static void finish(TResult verdict, string msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

void add_to_list(int w, int v) {
    pos_in_list[w] = (int)lists[v].size();
    lists[v].push_back(w);
}

void remove_from_list(int w, int v) {
    int idx = pos_in_list[w];
    int last_w = lists[v].back();

    lists[v][idx] = last_w;
    pos_in_list[last_w] = idx;
    lists[v].pop_back();
}

int count_window(int w) {
    int c = 0;
    for (int k = 0; k < 4; k++) {
        if (s[w + k] == 'b') c++;
    }
    return c;
}

void update_window(int w) {
    int old_v = val[w];
    remove_from_list(w, old_v);

    int new_v = count_window(w);
    val[w] = new_v;
    add_to_list(w, new_v);
}

int apply_move(int m) {

    int collected = 0;
    vector<int> affected_windows;

    for (int k = 0; k < 4; k++) {
        int idx = m + k;
        if (s[idx] == 'b') {
            collected++;
            s[idx] = '.';

            int start_w = max(0, idx - 3);
            int end_w = min(N - 4, idx);
            for (int w = start_w; w <= end_w; w++) {
                affected_windows.push_back(w);
            }
        }
    }

    if (!affected_windows.empty()) {
        sort(affected_windows.begin(), affected_windows.end());
        affected_windows.erase(unique(affected_windows.begin(), affected_windows.end()), affected_windows.end());
        for (int w : affected_windows) {
            update_window(w);
        }
    }

    berries_remaining -= collected;
    return collected;
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    N = inf.readInt();
    s = inf.readToken();

    if ((int)s.size() != N) {
        finish(_fail, "Input string length does not match N");
    }

    berries_remaining = 0;
    for (char c : s) if (c == 'b') berries_remaining++;

    query_limit = N;
    long long hard_cap = max(200000LL, 10LL * N);

    if (N >= 4) {
        val.resize(N - 3);
        pos_in_list.resize(N - 3);
        for (int i = 0; i <= N - 4; i++) {
            val[i] = count_window(i);
            add_to_list(i, val[i]);
        }
    }

    cout << N << endl;
    cout << s << endl;
    cout.flush();

    int turn = 0;

    while (berries_remaining > 0) {
        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded (infinite loop?)");
        }

        if (turn == 0) {
            int best_v = -1;

            for (int v = 4; v >= 0; v--) {
                if (!lists[v].empty()) {
                    best_v = v;
                    break;
                }
            }

            if (best_v == -1) break;

            int count = (int)lists[best_v].size();
            int r = get_rand_index(count);
            int move_idx = lists[best_v][r];

            int pts = apply_move(move_idx);
            grandpa_score += pts;

            cout << (move_idx + 1) << endl;

            turn = 1;
        } else {

            char c;
            while (cin.get(c) && isspace(c));
            if (cin.eof()) {
                finish(_wa, "Unexpected EOF waiting for Erik's move");
            }
            cin.putback(c);

            string token;
            if (!(cin >> token)) {
                finish(_wa, "Failed to read token");
            }

            if (token == "?") {
                if (!(cin >> token)) finish(_wa, "Expected number after '?'");
            } else if (token == "!") {
                finish(_pe, "Unexpected protocol token '!'");
            }

            int move_1 = 0;
            try {
                move_1 = stoi(token);
            } catch (...) {
                finish(_pe, "Move '" + token + "' is not a valid integer");
            }

            if (move_1 < 1 || move_1 > N - 3) {
                finish(_wa, "Move " + to_string(move_1) + " out of bounds [1, " + to_string(N-3) + "]");
            }

            queries++;

            int pts = apply_move(move_1 - 1);
            erik_score += pts;

            turn = 0;
        }
    }

    if (erik_score >= grandpa_score) {
        finish(_ok, "Erik " + to_string(erik_score) + " >= Grandpa " + to_string(grandpa_score));
    } else {
        finish(_wa, "Erik " + to_string(erik_score) + " < Grandpa " + to_string(grandpa_score));
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[]) {

    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");

    int n = opt<int>("n", 100000);

    if (n < 4) n = 4;
    if (n % 2 != 0) n++;

    int berries = n / 2;
    string s(n, '.');

    if (mode == "non") {

        for (int i = 0; i < berries; i++) {
            s[i] = 'b';
        }
        shuffle(s.begin(), s.end());
    } else {

        int type = rnd.next(1, 5);

        if (type == 1) {

            for (int i = 0; i < berries; i++) s[i] = 'b';

            int swaps = n / 50;
            for (int i = 0; i < swaps; i++) {
                int u = rnd.next(n);
                int v = rnd.next(n);
                swap(s[u], s[v]);
            }
        } else if (type == 2) {

            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) s[i] = 'b';
            }

            int swaps = n / 100;
            for (int i = 0; i < swaps; i++) {
                int u = rnd.next(n);
                int v = rnd.next(n);
                swap(s[u], s[v]);
            }
        } else if (type == 3) {

            for (int i = 0; i < n; i++) {
                if ((i % 8) < 4) s[i] = 'b';
            }

            int current_b = 0;
            for (char c : s) if (c == 'b') current_b++;

            vector<int> b_idx, dot_idx;
            for (int i = 0; i < n; i++) {
                if (s[i] == 'b') b_idx.push_back(i);
                else dot_idx.push_back(i);
            }
            shuffle(b_idx.begin(), b_idx.end());
            shuffle(dot_idx.begin(), dot_idx.end());

            while (current_b > berries) {
                s[b_idx.back()] = '.';
                b_idx.pop_back();
                current_b--;
            }
            while (current_b < berries) {
                s[dot_idx.back()] = 'b';
                dot_idx.pop_back();
                current_b++;
            }
        } else if (type == 4) {

            int current_b = 0;
            int ptr = 0;
            while (ptr < n) {
                int len = rnd.next(10, 200);
                if (ptr + len > n) len = n - ptr;

                bool dense = rnd.next(2);
                if (dense) {
                    for (int k = 0; k < len && current_b < berries; k++) {
                        s[ptr + k] = 'b';
                        current_b++;
                    }
                }
                ptr += len;
            }

            vector<int> dots;
            for (int i = 0; i < n; i++) if (s[i] == '.') dots.push_back(i);
            shuffle(dots.begin(), dots.end());
            int needed = berries - current_b;
            for (int i = 0; i < needed; i++) s[dots[i]] = 'b';
        } else {

            for (int i = n - berries; i < n; i++) s[i] = 'b';

            int swaps = n / 50;
            for (int i = 0; i < swaps; i++) {
                int u = rnd.next(n);
                int v = rnd.next(n);
                swap(s[u], s[v]);
            }
        }
    }

    cout << n << endl;
    cout << s << endl;

    return 0;
}


This is an interactive problem.

You are given a grid with $n$ rows and $m$ columns. You need to fill each cell with a unique integer from $1$ to $n \cdot m$.

After filling the grid, you will play a game on this grid against the interactor. Players take turns selecting one of the previously unselected cells from the grid, with the interactor going first.

On the first turn, the interactor can choose any cell from the grid. After that, any chosen cell must be orthogonally adjacent to at least one previously selected cell. Two cells are considered orthogonally adjacent if they share an edge. The game continues until all cells have been selected.

Your goal is to let the sum of numbers in the cells selected by you be strictly less than the sum of numbers in the cells selected by the interactor.

Input

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of test cases follows.

The only line of each test case contains two integers $n$ and $m$ ($4 \le n, m \le 10$) — the number of rows and columns in the grid.

Interaction

First, output $n$ lines, each containing $m$ integers, representing the integers that you filled in the grid. Each integer from $1$ to $n \cdot m$ should appear exactly once.

Then, the game begins. The interactor and you take turns outputting coordinates to select a cell for $n \times m$ turns, with the interactor starting first.

On each player's (either you or the interactor) turn, the player will output two integers $i$ and $j$ ($1 \le i \le n$, $1 \le j \le m$), denoting that the player has selected the cell on the $i$-th row and $j$-th column. This cell should not have been selected in a previous round. Additionally, if it is not the first turn, the cell must be orthogonally adjacent to at least one previously selected cell.

If any of your outputs are invalid, the jury will output "-1" and you will receive a Wrong Answer verdict.

At the end of all $n \cdot m$ turns, if the sum of numbers in the cells selected by you is not strictly less than the sum of numbers in the cells selected by the interactor, the jury will output "-1" and you will receive a Wrong Answer verdict.

If your program has received a Wrong Answer verdict, it must terminate immediately. Otherwise, you may receive an arbitrary verdict because your solution might be reading from a closed stream.

After outputting, 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.

Example

Input

```
1
4 4

3 4

4 4

4 2

4 1

1 4

1 2

2 2

2 1
```

Output

```
2 3 4 10
12 6 11 15
5 13 16 8
9 7 1 14

2 4

4 3

3 3

3 1

1 3

1 1

2 3

3 2
```

Note

Note that this is an example game and does not necessarily represent the optimal strategy for both players.

First, we fill a $4 \times 4$ grid with unique integers from $1$ to $16$ in the following way:

|  |  |  |  |
| --- | --- | --- | --- |
| $2$ | $3$ | $4$ | $10$ |
| $12$ | $6$ | $11$ | $15$ |
| $5$ | $13$ | $16$ | $8$ |
| $9$ | $7$ | $1$ | $14$ |

Next, the game begins.

1. The interactor first selects $(3, 4)$, which is the number $8$. For this selection, the interactor could choose any number. From the next selection onwards, each chosen number has to be adjacent to any previously selected number.
2. We select $(2, 4)$, which is the number $15$, adjacent to $(3, 4)$.
3. The interactor selects $(4, 4)$, which is the number $14$, adjacent to $(3, 4)$.
4. We select $(4, 3)$, which is the number $1$, adjacent to $(4, 4)$.
5. $\ldots$
6. This is continued until all numbers are selected.

In the end, the numbers we selected were $[15, 1, 16, 5, 4, 2, 11, 13]$, and the numbers selected by the interactor were $[8, 14, 7, 9, 10, 3, 6, 12]$. The sum of the numbers we selected is $67$, which is less than the sum of the numbers selected by the interactor $69$. Therefore, we have won this game.

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static bool parseLongLongStrict(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '-') {
        i = 1;
        if ((int)s.size() == 1) return false;
    }
    for (; i < (int)s.size(); i++) if (!isdigit((unsigned char)s[i])) return false;
    try {
        size_t idx = 0;
        long long v = stoll(s, &idx, 10);
        if (idx != s.size()) return false;
        out = v;
        return true;
    } catch (...) {
        return false;
    }
}

static long long readLLFromCinOrFinish(const string& what) {
    string tok;
    if (!(cin >> tok)) {
        cout << -1 << endl;
        finish(_pe, "Unexpected EOF while reading " + what);
    }
    long long x;
    if (!parseLongLongStrict(tok, x)) {
        cout << -1 << endl;
        finish(_pe, "Malformed integer while reading " + what);
    }
    return x;
}

struct TestCase {
    int n = 0, m = 0;
    vector<pair<int,int>> path;
};

static bool adjacent4(int r1, int c1, int r2, int c2) {
    return (abs(r1 - r2) + abs(c1 - c2)) == 1;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    int t = inf.readInt(1, 100, "t");
    vector<TestCase> tests;
    tests.reserve(t);

    long long totalContestantMoves = 0;
    for (int tc = 0; tc < t; tc++) {
        TestCase cs;
        cs.n = inf.readInt(4, 10, "n");
        cs.m = inf.readInt(4, 10, "m");
        int N = cs.n * cs.m;
        cs.path.reserve(N);
        vector<vector<int>> seen(cs.n, vector<int>(cs.m, 0));
        for (int k = 0; k < N; k++) {
            int r = inf.readInt(1, cs.n, "path_r") - 1;
            int c = inf.readInt(1, cs.m, "path_c") - 1;
            if (seen[r][c]) finish(_pe, "Hidden path has duplicates");
            seen[r][c] = 1;
            cs.path.push_back({r, c});
            if (k > 0) {
                auto [pr, pc] = cs.path[k - 1];
                if (!adjacent4(pr, pc, r, c)) finish(_pe, "Hidden path is not consecutive-adjacent");
            }
        }
        tests.push_back(std::move(cs));
        totalContestantMoves += (long long)(tests.back().n * tests.back().m) / 2;
    }

    query_limit = totalContestantMoves;
    log_metrics();

    const long long hard_cap = max(200000LL, 10LL * max(1LL, query_limit));

    cout << t << endl;

    for (int tc = 0; tc < t; tc++) {
        const int n = tests[tc].n, m = tests[tc].m;
        const int N = n * m;
        const auto& path = tests[tc].path;

        cout << n << " " << m << endl;

        vector<vector<int>> a(n, vector<int>(m, 0));
        vector<char> used(N + 1, 0);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                long long vll = readLLFromCinOrFinish("grid value");
                if (vll < 1 || vll > N) {
                    cout << -1 << endl;
                    finish(_wa, "Grid value out of range");
                }
                int v = (int)vll;
                if (used[v]) {
                    cout << -1 << endl;
                    finish(_wa, "Grid value duplicated");
                }
                used[v] = 1;
                a[i][j] = v;
            }
        }

        vector<vector<char>> selected(n, vector<char>(m, 0));
        long long sumInter = 0, sumCont = 0;
        int p = 0;

        auto pickInteractor = [&]() -> pair<int,int> {
            while (p < N && selected[path[p].first][path[p].second]) p++;
            if (p >= N) finish(_pe, "No available move for interactor (should not happen)");
            return path[p];
        };

        auto isAdjacentToSelected = [&](int r, int c) -> bool {
            static const int dr[4] = {1, -1, 0, 0};
            static const int dc[4] = {0, 0, 1, -1};
            for (int k = 0; k < 4; k++) {
                int nr = r + dr[k], nc = c + dc[k];
                if (0 <= nr && nr < n && 0 <= nc && nc < m && selected[nr][nc]) return true;
            }
            return false;
        };

        for (int turn = 0; turn < N; turn++) {
            if (turn % 2 == 0) {

                auto [r, c] = pickInteractor();
                if (turn > 0 && !isAdjacentToSelected(r, c)) finish(_pe, "Interactor move not adjacent (hidden path invariant broken)");
                selected[r][c] = 1;
                sumInter += a[r][c];
                cout << (r + 1) << " " << (c + 1) << endl;
            } else {

                long long iLL = readLLFromCinOrFinish("contestant row");
                long long jLL = readLLFromCinOrFinish("contestant col");
                queries++;
                if (queries > hard_cap) {
                    cout << -1 << endl;
                    finish(_pe, "Hard cap exceeded");
                }

                if (iLL == -1 || jLL == -1) {
                    cout << -1 << endl;
                    finish(_wa, "Contestant terminated with -1");
                }

                if (iLL < 1 || iLL > n || jLL < 1 || jLL > m) {
                    cout << -1 << endl;
                    finish(_wa, "Move out of bounds");
                }
                int r = (int)iLL - 1, c = (int)jLL - 1;

                if (selected[r][c]) {
                    cout << -1 << endl;
                    finish(_wa, "Cell already selected");
                }
                if (!isAdjacentToSelected(r, c)) {
                    cout << -1 << endl;
                    finish(_wa, "Move not adjacent to selected set");
                }

                selected[r][c] = 1;
                sumCont += a[r][c];
            }
        }

        if (!(sumCont < sumInter)) {
            cout << -1 << endl;
            finish(_wa, "Final sum condition failed");
        }
    }

    finish(_ok, "OK");
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static bool readIntFromContestant(long long& x) {
    cin >> x;
    return (bool)cin;
}

struct MoveEval {
    long long delta;
    int minOpp;
    int frontierSize;
    int ourVal;
    int r, c;
};

static bool betterForInteractor(const MoveEval& a, const MoveEval& b) {
    if (a.delta != b.delta) return a.delta < b.delta;
    if (a.minOpp != b.minOpp) return a.minOpp > b.minOpp;
    if (a.frontierSize != b.frontierSize) return a.frontierSize < b.frontierSize;
    if (a.ourVal != b.ourVal) return a.ourVal < b.ourVal;
    if (a.r != b.r) return a.r < b.r;
    return a.c < b.c;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    int t = inf.readInt(1, 100, "t");
    vector<pair<int,int>> tests;
    tests.reserve(t);

    long long totalContestantMoves = 0;
    for (int tc = 0; tc < t; tc++) {
        int n = inf.readInt(4, 10, "n");
        int m = inf.readInt(4, 10, "m");
        tests.push_back({n, m});
        totalContestantMoves += (1LL * n * m) / 2;
    }

    query_limit = totalContestantMoves;
    log_metrics();

    cout << t << "\n";
    cout.flush();

    const long long hard_cap = max(200000LL, 10LL * query_limit);

    for (int tc = 0; tc < t; tc++) {
        int n = tests[tc].first;
        int m = tests[tc].second;
        int nm = n * m;

        cout << n << " " << m << "\n";
        cout.flush();

        vector<vector<int>> val(n, vector<int>(m, 0));
        vector<char> seen(nm + 1, 0);

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                long long xll;
                if (!readIntFromContestant(xll)) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_pe, "EOF / non-integer while reading grid");
                }
                if (xll < 1 || xll > nm) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_wa, "grid value out of range");
                }
                int x = (int)xll;
                if (seen[x]) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_wa, "duplicate value in grid");
                }
                seen[x] = 1;
                val[i][j] = x;
            }
        }

        vector<vector<char>> picked(n, vector<char>(m, 0));
        int pickedCount = 0;
        long long sumInteractor = 0, sumContestant = 0;

        auto adjPicked = [&](int r, int c) -> bool {
            static const int dr[4] = {1, -1, 0, 0};
            static const int dc[4] = {0, 0, 1, -1};
            for (int k = 0; k < 4; k++) {
                int nr = r + dr[k], nc = c + dc[k];
                if (0 <= nr && nr < n && 0 <= nc && nc < m && picked[nr][nc]) return true;
            }
            return false;
        };

        auto chooseInteractorMove = [&]() -> pair<int,int> {
            MoveEval best;
            bool have = false;

            for (int r = 0; r < n; r++) {
                for (int c = 0; c < m; c++) {
                    if (picked[r][c]) continue;
                    if (pickedCount != 0 && !adjPicked(r, c)) continue;

                    int ourV = val[r][c];

                    picked[r][c] = 1;
                    int minOpp = INT_MAX;
                    int frontierSize = 0;

                    if (pickedCount + 1 < nm) {
                        for (int rr = 0; rr < n; rr++) {
                            for (int cc = 0; cc < m; cc++) {
                                if (picked[rr][cc]) continue;
                                if (!adjPicked(rr, cc)) continue;
                                frontierSize++;
                                minOpp = min(minOpp, val[rr][cc]);
                            }
                        }
                        if (minOpp == INT_MAX) {

                            minOpp = 0;
                            frontierSize = 0;
                        }
                    } else {
                        minOpp = 0;
                        frontierSize = 0;
                    }

                    picked[r][c] = 0;

                    MoveEval cur;
                    cur.delta = 1LL * ourV - 1LL * minOpp;
                    cur.minOpp = minOpp;
                    cur.frontierSize = frontierSize;
                    cur.ourVal = ourV;
                    cur.r = r;
                    cur.c = c;

                    if (!have || betterForInteractor(cur, best)) {
                        best = cur;
                        have = true;
                    }
                }
            }

            if (!have) finish(_fail, "interactor has no legal move (internal error)");
            return {best.r, best.c};
        };

        for (int turn = 0; turn < nm; turn++) {
            if (turn % 2 == 0) {
                auto [r, c] = chooseInteractorMove();
                picked[r][c] = 1;
                pickedCount++;
                sumInteractor += val[r][c];

                cout << (r + 1) << " " << (c + 1) << "\n";
                cout.flush();
            } else {
                long long iLL, jLL;
                if (!readIntFromContestant(iLL) || !readIntFromContestant(jLL)) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_pe, "EOF / non-integer on contestant move");
                }
                queries++;
                if (queries > hard_cap) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_pe, "too many queries (hard cap exceeded)");
                }

                if (iLL < 1 || iLL > n || jLL < 1 || jLL > m) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_wa, "contestant move out of bounds");
                }
                int r = (int)iLL - 1;
                int c = (int)jLL - 1;

                if (picked[r][c]) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_wa, "contestant picked an already selected cell");
                }
                if (!adjPicked(r, c)) {
                    cout << -1 << "\n";
                    cout.flush();
                    finish(_wa, "contestant move not adjacent to selected region");
                }

                picked[r][c] = 1;
                pickedCount++;
                sumContestant += val[r][c];
            }
        }

        if (pickedCount != nm) finish(_fail, "pickedCount mismatch (internal error)");
        if (!(sumContestant < sumInteractor)) {
            cout << -1 << "\n";
            cout.flush();
            finish(_wa, "final sum condition failed");
        }
    }

    finish(_ok, "OK");
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static vector<pair<int,int>> makeSnakeRows(int n, int m) {
    vector<pair<int,int>> path;
    path.reserve(n * m);
    for (int r = 0; r < n; r++) {
        if (r % 2 == 0) {
            for (int c = 0; c < m; c++) path.push_back({r, c});
        } else {
            for (int c = m - 1; c >= 0; c--) path.push_back({r, c});
        }
    }
    return path;
}

static vector<pair<int,int>> makeSnakeCols(int n, int m) {
    vector<pair<int,int>> path;
    path.reserve(n * m);
    for (int c = 0; c < m; c++) {
        if (c % 2 == 0) {
            for (int r = 0; r < n; r++) path.push_back({r, c});
        } else {
            for (int r = n - 1; r >= 0; r--) path.push_back({r, c});
        }
    }
    return path;
}

static vector<pair<int,int>> makeSpiral(int n, int m, int sr, int sc, int dir0) {

    static const int dr[4] = {0, 1, 0, -1};
    static const int dc[4] = {1, 0, -1, 0};

    vector<vector<char>> vis(n, vector<char>(m, 0));
    vector<pair<int,int>> path;
    path.reserve(n * m);

    int r = sr, c = sc, dir = dir0;
    for (int step = 0; step < n * m; step++) {
        vis[r][c] = 1;
        path.push_back({r, c});
        if (step + 1 == n * m) break;

        for (int tries = 0; tries < 4; tries++) {
            int nr = r + dr[dir], nc = c + dc[dir];
            if (0 <= nr && nr < n && 0 <= nc && nc < m && !vis[nr][nc]) {
                r = nr; c = nc;
                break;
            }
            dir = (dir + 1) & 3;
        }
    }
    return path;
}

static bool isAdjacent(const pair<int,int>& a, const pair<int,int>& b) {
    return (abs(a.first - b.first) + abs(a.second - b.second)) == 1;
}

static void ensureHamiltonianAdjacency(const vector<pair<int,int>>& path, int n, int m) {
    if ((int)path.size() != n * m) quitf(_fail, "Path size mismatch");
    vector<vector<int>> seen(n, vector<int>(m, 0));
    for (auto [r, c] : path) {
        if (r < 0 || r >= n || c < 0 || c >= m) quitf(_fail, "Out of bounds in path");
        if (seen[r][c]) quitf(_fail, "Duplicate cell in path");
        seen[r][c] = 1;
    }
    for (int i = 1; i < (int)path.size(); i++) {
        if (!isAdjacent(path[i - 1], path[i])) quitf(_fail, "Non-adjacent consecutive cells");
    }
}

int main(int argc, char** argv) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", -1);
    int mOpt = opt<int>("m", -1);

    int seed = 1;
    if (argc >= 2) {
        seed = atoi(argv[1]);
        if (seed <= 0) seed = 1;
    }

    int n, m;

    if (nOpt != -1 && mOpt != -1) {
        n = nOpt;
        m = mOpt;
    } else if (seed == 1) {
        n = 4; m = 4;
    } else if (seed == 2) {
        n = 4; m = 10;
    } else if (seed == 3) {
        n = 10; m = 4;
    } else {

        int pick = rnd.next(0, 11);
        vector<pair<int,int>> candidates = {
            {10, 10}, {10, 9}, {9, 10}, {9, 9},
            {10, 8}, {8, 10}, {10, 7}, {7, 10},
            {8, 9}, {9, 8}, {10, 6}, {6, 10}
        };
        n = candidates[pick].first;
        m = candidates[pick].second;
        if (rnd.next(0, 3) == 0) swap(n, m);
    }

    n = max(4, min(10, n));
    m = max(4, min(10, m));

    cout << 1 << "\n";
    cout << n << " " << m << "\n";

    if (mode == "non") {

        vector<pair<int,int>> path;

        if (seed <= 3) {

            int corner = (seed - 1) % 4;
            int sr = (corner >= 2) ? (n - 1) : 0;
            int sc = (corner % 2) ? (m - 1) : 0;

            int dir0;
            if (sr == 0 && sc == 0) dir0 = 0;
            else if (sr == 0 && sc == m - 1) dir0 = 1;
            else if (sr == n - 1 && sc == m - 1) dir0 = 2;
            else dir0 = 3;
            path = makeSpiral(n, m, sr, sc, dir0);
        } else {
            int type = rnd.next(0, 2);
            if (type == 0) {
                path = makeSnakeRows(n, m);
                if (rnd.next(0, 1) == 1) reverse(path.begin(), path.end());
            } else if (type == 1) {
                path = makeSnakeCols(n, m);
                if (rnd.next(0, 1) == 1) reverse(path.begin(), path.end());
            } else {
                int corner = rnd.next(0, 3);
                int sr = (corner >= 2) ? (n - 1) : 0;
                int sc = (corner % 2) ? (m - 1) : 0;
                int dir0;
                if (sr == 0 && sc == 0) dir0 = 0;
                else if (sr == 0 && sc == m - 1) dir0 = 1;
                else if (sr == n - 1 && sc == m - 1) dir0 = 2;
                else dir0 = 3;

                dir0 = (dir0 + rnd.next(0, 1)) & 3;
                path = makeSpiral(n, m, sr, sc, dir0);
                if (rnd.next(0, 2) == 0) reverse(path.begin(), path.end());
            }
        }

        ensureHamiltonianAdjacency(path, n, m);

        for (auto [r, c] : path) {
            cout << (r + 1) << " " << (c + 1) << "\n";
        }
    } else if (mode == "adp") {

    } else {

    }

    return 0;
}


# This is an interactive problem.

Grammy has a directed cyclic graph of $n$ vertices ( $1 \leq n \leq 1 0 ^ { 9 }$ ) numbered from 1 to $n$ . A directed cyclic graph is a directed graph of $n$ vertices that form one cycle. Specifically, there are $n$ vertices and $n$ edges in the graph, and there exists a permutation $p _ { 1 } , p _ { 2 } , \ldots , p _ { n }$ such that there is a one-way edge from $p _ { i }$ to

$p ( i \mathrm { m o d } n ) { + } 1$

Initially, there is a token on a predetermined vertex.

You can ask Grammy to move the token in the following way:

“walk $\tt { x } ^ { \prime \prime }$ where $0 \leq x \leq 1 0 ^ { 9 }$ . In response to the query, Grammy will move the token through exactly edges and tell you the position of the token after moving.

You win if you guess the number of vertices in the hidden graph (number $n$ ) by making no more than $1 0 ^ { 4 }$ queries.

The vertices in the graph and the initial position of the token are fixed in advance.

# Interaction Protocol

You can make no more than $1 0 ^ { 4 }$ queries. To make a query, output “walk x” ( $0 \leq x \leq 1 0 ^ { 9 }$ ) on a separate line, then you should read the response from standard input.

In response to the query, the interactor will move the token through exactly $x$ edges and output the position of the token after moving.

To give your answer, print “guess n” on a separate line, where $n$ is the size of the hidden graph $1 \leq n \leq 1 0 ^ { 9 }$ ). The output of the answer is not counted towards the limit of $1 0 ^ { 4 }$ queries.

After that, your program should terminate.

After printing a query, do not forget to output end of line and flush the output. To do this, use fflush(stdout) or cout.flush() in $\mathrm { C } + +$ , System.out.flush() in Java, flush(output) in Pascal, or stdout.flush() in Python.

It is guaranteed that the vertices in the graph and the initial position of the token are fixed in advance.

# Example

standard input	standard output

3	walk 0

	walk 1

10	walk 2

4	walk 3

5	walk 4

3

5	walk 6 guess 10

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;

static const long long query_limit = 10000;

static const long long hard_cap = 20000;

void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char* argv[]) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    long long n = inf.readLong();
    long long start_pos = inf.readLong();
    int label_type = inf.readInt();
    long long seed_val = inf.readLong();

    log_metrics();

    long long current_index = start_pos;
    vector<int> p;

    if (label_type == 1) {

        if (n <= 20000000) {
            p.resize(n);
            iota(p.begin(), p.end(), 1);

            mt19937_64 rng(seed_val);
            shuffle(p.begin(), p.end(), rng);
        } else {

            label_type = 0;
        }
    }

    while (true) {

        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded");
        }

        string token;

        if (!(cin >> token)) {

            finish(_wa, "Unexpected EOF (did not guess n)");
        }

        bool is_query = false;
        bool is_answer = false;
        long long val = -1;

        string lower_token = token;
        transform(lower_token.begin(), lower_token.end(), lower_token.begin(), ::tolower);

        if (lower_token == "walk" || token == "?") {
            is_query = true;
            if (!(cin >> val)) finish(_pe, "Expected number after walk/? token");
        } else if (lower_token == "guess" || token == "!") {
            is_answer = true;
            if (!(cin >> val)) finish(_pe, "Expected number after guess/! token");
        } else {

            try {
                size_t idx;
                val = stoll(token, &idx);
                if (idx != token.size()) {

                    finish(_pe, ("Invalid token: " + token).c_str());
                }
                is_query = true;
            } catch (...) {
                finish(_pe, ("Invalid token: " + token).c_str());
            }
        }

        if (is_query) {
            if (val < 0) finish(_pe, "Walk distance must be non-negative");

            current_index = (current_index + val) % n;

            int label;
            if (label_type == 0) {

                label = (int)(current_index + 1);
            } else {

                label = p[current_index];
            }

            cout << label << endl;
            queries++;

            if (queries % 100 == 0) log_metrics();

        } else if (is_answer) {

            if (val == n) {
                finish(_ok, "Correct guess");
            } else {
                finish(_wa, "Wrong guess");
            }
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");

    long long seed_val = rnd.next(1LL, 1000000000000000000LL);

    if (mode == "non") {
        long long n = -1;

        if (has_opt("n")) {
            n = opt<long long>("n");
        } else {

            int type = rnd.next(1, 100);

            if (type <= 5) {

                n = rnd.next(1, 10);
            } else if (type <= 10) {

                int p = rnd.next(1, 9);
                long long base = 1;
                for(int k=0; k<p; k++) base *= 10;
                n = base + rnd.next(-2, 2);
                if (n < 1) n = 1;
            } else if (type <= 20) {

                n = 1000000000LL - rnd.next(0, 100);
            } else if (type <= 25) {

                n = 999999937;
            } else if (type <= 60) {

                n = rnd.next(1000000LL, 1000000000LL);
            } else {

                long long lower = 1;
                long long upper = 1000000000LL;

                long long log_range = rnd.next(0, 9);
                long long range_start = 1;
                for(int k=0; k<log_range; k++) range_start *= 10;
                long long range_end = range_start * 10 - 1;
                if (range_end > upper) range_end = upper;
                n = rnd.next(range_start, range_end);
            }
        }

        long long start_pos = rnd.next(0LL, n - 1);

        int label_type = 0;
        if (has_opt("type")) {
            label_type = opt<int>("type");
        } else {

            if (n <= 20000000) label_type = 1;
            else label_type = 0;

            if (rnd.next(1, 20) == 1) label_type = 1 - label_type;
        }

        cout << n << " " << start_pos << " " << label_type << " " << seed_val << endl;

    } else if (mode == "adp") {

        long long min_n = opt<long long>("min_n", 1);
        long long max_n = opt<long long>("max_n", 1000000000);
        int label_type = opt<int>("type", 0);

        cout << min_n << " " << max_n << " " << label_type << " " << seed_val << endl;
    }

    return 0;
}


This is an interactive problem.

Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.

Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.

Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x<y$, $0$, if $x=y$, and $1$, if $x>y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.

In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.

You can ask the rocket no more than $60$ questions.

Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.

Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers).

Input

The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$.

Interaction

You can ask the rocket no more than $60$ questions.

To ask a question, print a number $y$ ($1\le y\le m$) and an end-of-line character, then do the operation flush and read the answer to the question.

If the program reads $0$, then the distance is correct and you must immediately terminate the program (for example, by calling exit(0)). If you ignore this, you can get any verdict, since your program will continue to read from the closed input stream.

If at some point your program reads $-2$ as an answer, it must immediately end (for example, by calling exit(0)). You will receive the "Wrong answer" verdict, and this will mean that the request is incorrect or the number of requests exceeds $60$. If you ignore this, you can get any verdict, since your program will continue to read from the closed input stream.

If your program's request is not a valid integer between $-2^{31}$ and $2^{31}-1$ (inclusive) without leading zeros, then you can get any verdict.

You can get "Idleness limit exceeded" if you don't print anything or if you forget to flush the output.

To flush the output buffer you can use (after printing a query and end-of-line):

* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* See the documentation for other languages.

Example

Input

```
5 2
1
-1
-1
1
0
```

Output

```
1
2
4
5
3
```

Really:

on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;

on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;

on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;

on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;

on the fifth query ($3$) the correct and incorrect answer is $0$.

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static bool parseStrictInt32(const string& s, int& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        i = 1;
        if ((int)s.size() == 1) return false;
    }
    for (int j = i; j < (int)s.size(); j++) {
        if (s[j] < '0' || s[j] > '9') return false;
    }
    if (i < (int)s.size() && s[i] == '0' && (int)s.size() - i > 1) return false;
    if (neg && (int)s.size() - i == 1 && s[i] == '0') return false;

    long long val = 0;
    for (int j = i; j < (int)s.size(); j++) {
        val = val * 10 + (s[j] - '0');
        if (!neg && val > (long long)INT_MAX) return false;
        if (neg && val > 2147483648LL) return false;
    }
    if (!neg) {
        out = (int)val;
        return true;
    } else {
        if (val == 2147483648LL) out = INT_MIN;
        else out = -(int)val;
        return true;
    }
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    try {
        long long m = inf.readLong();
        int n = inf.readInt();
        long long x = inf.readLong();
        string p = inf.readToken();

        if (m < 1 || m > 1000000000LL) finish(_pe, "Invalid m in input.");
        if (n < 1 || n > 30) finish(_pe, "Invalid n in input.");
        if (x < 1 || x > m) finish(_pe, "Invalid x in input.");
        if ((int)p.size() != n) finish(_pe, "Invalid p length in input.");
        for (char c : p) if (c != '0' && c != '1') finish(_pe, "Invalid p character in input.");

        query_limit = 60;
        log_metrics();

        const long long hard_cap = max(200000LL, 10LL * query_limit);

        cout << m << " " << n << "\n";
        cout.flush();

        int idx = 0;
        while (true) {
            if (queries >= hard_cap) finish(_pe, "Hard cap exceeded (possible infinite loop).");

            string tok;
            if (!(cin >> tok)) {
                finish(_wa, "Contestant terminated without receiving answer 0.");
            }

            int y32;
            if (!parseStrictInt32(tok, y32)) {

                try {
                    cout << -2 << "\n";
                    cout.flush();
                } catch (...) {}
                finish(_wa, "Invalid integer format in query.");
            }

            long long y = (long long)y32;
            queries++;

            if (queries > query_limit) {
                try {
                    cout << -2 << "\n";
                    cout.flush();
                } catch (...) {}
                finish(_wa, "Query limit exceeded.");
            }

            if (y < 1 || y > m) {
                try {
                    cout << -2 << "\n";
                    cout.flush();
                } catch (...) {}
                finish(_wa, "Query out of range.");
            }

            int t = 0;
            if (x < y) t = -1;
            else if (x > y) t = 1;
            else t = 0;

            int ans = t;
            if (t != 0 && p[idx] == '0') ans = -t;

            cout << ans << "\n";
            cout.flush();

            idx++;
            if (idx == n) idx = 0;

            if (t == 0) {
                finish(_ok, "OK");
            }
        }
    } catch (const std::exception& e) {
        finish(_pe, string("Exception: ") + e.what());
    } catch (...) {
        finish(_pe, "Unknown exception.");
    }
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << '\n';
        tout << "query_limit=" << query_limit << '\n';
        tout.flush();
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

struct SplitMix64 {
    uint64_t x;
    explicit SplitMix64(uint64_t seed) : x(seed) {}
    uint64_t next() {
        uint64_t z = (x += 0x9e3779b97f4a7c15ULL);
        z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
        z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
        return z ^ (z >> 31);
    }
};

static bool parseInt32TokenStrict(const string& s, long long& out) {
    if (s.empty()) return false;
    int pos = 0;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        pos = 1;
        if (pos >= (int)s.size()) return false;
    }
    if (s[pos] == '0' && (int)s.size() - pos > 1) return false;
    unsigned long long v = 0;
    for (int i = pos; i < (int)s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        v = v * 10ULL + (unsigned long long)(c - '0');
        if (!neg && v > 2147483647ULL) return false;
        if (neg && v > 2147483648ULL) return false;
    }
    if (neg && v == 0ULL) return false;
    out = neg ? -(long long)v : (long long)v;
    return true;
}

static long long m = 0;
static int n = 0;

static bool fixed_instance = false;
static bool decided = false;
static long long x_hidden = -1;
static vector<int> p_bits;
static long long query_index = 0;

static void decide_instance(long long first_y) {
    uint64_t seed = 0x243f6a8885a308d3ULL;
    seed ^= (uint64_t)m + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2);
    seed ^= (uint64_t)(unsigned)n + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2);
    seed ^= (uint64_t)first_y + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2);

    SplitMix64 rng(seed);

    p_bits.assign(n, 1);
    for (int i = 0; i < n; i++) {

        int bit = ((int)(rng.next() % 100ULL) < 38) ? 1 : 0;
        p_bits[i] = bit;
    }
    if (n > 1) {
        bool has0 = false, has1 = false;
        for (int b : p_bits) has0 |= (b == 0), has1 |= (b == 1);
        if (!has0) p_bits[(int)(rng.next() % (uint64_t)n)] = 0;
        if (!has1) p_bits[(int)(rng.next() % (uint64_t)n)] = 1;
    }

    if (m == 1) {
        x_hidden = 1;
    } else {
        long long base;
        if (m >= 2) {
            unsigned long long span = (unsigned long long)(m - 1);
            base = 2 + (long long)(rng.next() % span);
        } else {
            base = 1;
        }
        if (base == first_y) {
            if (base < m) base++;
            else base--;
        }
        if (base < 1) base = 1;
        if (base > m) base = m;
        x_hidden = base;
    }

    decided = true;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    try {
        m = inf.readLong(1, 1000000000LL, "m");
        n = inf.readInt(1, 30, "n");

        query_limit = 60;
        log_metrics();

        if (!inf.seekEof()) {
            long long x_in = inf.readLong();
            string p_in = "";
            if (!inf.seekEof()) p_in = inf.readToken();

            if (x_in < 1 || x_in > m) {

                x_in = min(max(1LL, x_in), m);
            }
            vector<int> bits(n, 1);
            bool ok = ((int)p_in.size() == n);
            if (ok) {
                for (int i = 0; i < n; i++) {
                    if (p_in[i] == '0') bits[i] = 0;
                    else if (p_in[i] == '1') bits[i] = 1;
                    else { ok = false; break; }
                }
            }
            if (!ok) {
                for (int i = 0; i < n; i++) bits[i] = (i & 1);
            }

            fixed_instance = true;
            decided = true;
            x_hidden = x_in;
            p_bits = std::move(bits);
        } else {
            fixed_instance = false;
            decided = false;
            p_bits.clear();
            x_hidden = -1;
        }

        cout << m << " " << n << endl;

        const long long hard_cap = max(200000LL, 10LL * query_limit);

        while (true) {
            string tok;
            if (!(cin >> tok)) {
                finish(_wa, "contestant terminated without receiving 0");
            }

            long long y_ll = 0;
            if (!parseInt32TokenStrict(tok, y_ll)) {

                finish(_pe, "invalid integer token");
            }

            if (y_ll < 1 || y_ll > m) {
                cout << -2 << endl;
                finish(_pe, "query out of range");
            }

            long long y = y_ll;

            if (!decided) {
                decide_instance(y);
            }

            int truth = 0;
            if (x_hidden < y) truth = -1;
            else if (x_hidden > y) truth = 1;
            else truth = 0;

            int bit = p_bits[(int)(query_index % (long long)n)];
            query_index++;
            queries++;
            if (queries > hard_cap) {
                finish(_pe, "too many queries (hard cap exceeded)");
            }

            int ans = (truth == 0 ? 0 : (bit ? truth : -truth));

            cout << ans << endl;

            if (ans == 0) {
                finish(_ok, "found x");
            }
        }
    } catch (const std::exception& e) {
        finish(_pe, string("exception: ") + e.what());
    } catch (...) {
        finish(_pe, "unknown exception");
    }
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static string makeStructuredPattern(int n) {
    vector<int> p(n, 1);

    for (int i = 0; i < n; i++) p[i] = (rnd.next(0, 99) < 62 ? 0 : 1);

    int blocks = rnd.next(3, 7);
    int pos = 0;
    for (int b = 0; b < blocks && pos < n; b++) {
        int len = rnd.next(2, 8);
        int bit = (b % 2 == 0 ? 0 : 1);
        if (rnd.next(0, 99) < 35) bit ^= 1;
        for (int k = 0; k < len && pos < n; k++, pos++) p[pos] = bit;
    }
    while (pos < n) {
        p[pos] = (rnd.next(0, 99) < 55 ? 0 : 1);
        pos++;
    }

    string s;
    s.reserve(n);
    for (int v : p) s.push_back(char('0' + v));
    return s;
}

static string makeAlternating(int n, int start) {
    string s;
    s.reserve(n);
    for (int i = 0; i < n; i++) s.push_back(char('0' + ((start + i) & 1)));
    return s;
}

static string makeAll(int n, char bit) { return string(n, bit); }

static string makeBiasedRandom(int n, int p_one_percent) {
    p_one_percent = max(0, min(100, p_one_percent));
    string s;
    s.reserve(n);
    for (int i = 0; i < n; i++) s.push_back(rnd.next(0, 99) < p_one_percent ? '1' : '0');
    return s;
}

static string makePattern(int n, int kind) {

    switch (kind) {
        case 0: return makeAll(n, '0');
        case 1: return makeAll(n, '1');
        case 2: return makeAlternating(n, 0);
        case 3: return makeAlternating(n, 1);
        case 4: return makeBiasedRandom(n, 20);
        case 5: return makeBiasedRandom(n, 80);
        case 6: return makeStructuredPattern(n);
        default: return makeBiasedRandom(n, 50);
    }
}

int main(int argc, char** argv) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int custom = opt<int>("custom", 0);

    if (mode != "non" && mode != "adp") {
        mode = "non";
    }

    if (mode != "non" && mode != "adp") mode = "non";

    long long m = opt<long long>("m", 1000000000LL);
    int n = opt<int>("n", 30);
    long long x = opt<long long>("x", -1);
    string p = opt<string>("p", "");

    int seedInt = atoi(argv[1]);

    if (!custom) {

        if (seedInt == 1) {
            m = 1;
            n = 1;
            x = 1;
            p = "1";
        } else if (seedInt == 2) {
            m = 1000000000LL;
            n = 30;
            x = m;
            p = makePattern(n, 0);
        } else if (seedInt == 3) {
            m = 1000000000LL;
            n = 30;
            x = 2;
            p = makePattern(n, 1);
        } else if (seedInt == 4) {
            m = 1000000000LL;
            n = 30;
            x = m - 1;
            p = makePattern(n, 2);
        } else if (seedInt == 5) {
            m = 2;
            n = 30;
            x = 2;
            p = makePattern(n, 3);
        } else {
            m = 1000000000LL;
            n = (seedInt % 7 == 0 ? 29 : 30);

            int xKind = seedInt % 8;
            if (xKind == 0) x = 1;
            else if (xKind == 1) x = 2;
            else if (xKind == 2) x = m;
            else if (xKind == 3) x = m - 1;
            else if (xKind == 4) x = m / 2;
            else if (xKind == 5) x = m / 2 + 1;
            else x = rnd.next(2LL, m);

            int pat = seedInt % 7;
            p = makePattern(n, pat);
        }
    }

    m = max(1LL, min(1000000000LL, m));
    n = max(1, min(30, n));

    if (x < 1 || x > m) {
        x = (m == 1 ? 1 : rnd.next(1LL, m));
    }

    if ((int)p.size() != n) {
        p = makePattern(n, 6);
    } else {
        for (char& c : p) {
            if (c != '0' && c != '1') c = (rnd.next(0, 1) ? '1' : '0');
        }
    }

    cout << m << " " << n << "\n";
    cout << x << "\n";
    cout << p << "\n";
    return 0;
}


This is an interactive problem.

After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem, Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortunately, the excess sauce disoriented him, and he's now lost!

The United States of America can be modeled as a tree (why though) with $n$ vertices. The tree is rooted at vertex $r$, wherein lies Kuroni's hotel.

Kuroni has a phone app designed to help him in such emergency cases. To use the app, he has to input two vertices $u$ and $v$, and it'll return a vertex $w$, which is the lowest common ancestor of those two vertices.

However, since the phone's battery has been almost drained out from live-streaming Kuroni's celebration party, he could only use the app at most $\lfloor \frac{n}{2} \rfloor$ times. After that, the phone would die and there will be nothing left to help our dear friend! :(

As the night is cold and dark, Kuroni needs to get back, so that he can reunite with his comfy bed and pillow(s). Can you help him figure out his hotel's location?

Interaction

The interaction starts with reading a single integer $n$ ($2 \le n \le 1000$), the number of vertices of the tree.

Then you will read $n-1$ lines, the $i$-th of them has two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$, $x_i \ne y_i$), denoting there is an edge connecting vertices $x_i$ and $y_i$. It is guaranteed that the edges will form a tree.

Then you can make queries of type "? u v" ($1 \le u, v \le n$) to find the lowest common ancestor of vertex $u$ and $v$.

After the query, read the result $w$ as an integer.

In case your query is invalid or you asked more than $\lfloor \frac{n}{2} \rfloor$ queries, the program will print $-1$ and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.

When you find out the vertex $r$, print "! $r$" and quit after that. This query does not count towards the $\lfloor \frac{n}{2} \rfloor$ limit.

Note that the tree is fixed beforehand and will not change during the queries, i.e. the interactor is not adaptive.

After printing any query do not forget to print end of line and flush the output. Otherwise, you might 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.

Example

Input

```
6
1 4
4 2
5 3
6 3
2 3

3

4

4
```

Output

```
? 5 6

? 3 1

? 1 2

! 4
```

Note

Note that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.

The image below demonstrates the tree in the sample test:

![](https://espresso.codeforces.com/df1619f848490908fe36e4d1a2431126f2b546c3.png)

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static bool readIntFromCin(long long &x) {

    string s;
    if (!(cin >> s)) return false;
    if (s.empty()) return false;

    int i = 0;
    bool neg = false;
    if (s[i] == '+' || s[i] == '-') {
        neg = (s[i] == '-');
        i++;
    }
    if (i >= (int)s.size()) return false;

    long long val = 0;
    for (; i < (int)s.size(); i++) {
        if (s[i] < '0' || s[i] > '9') return false;
        int d = s[i] - '0';
        if (val > (LLONG_MAX - d) / 10) return false;
        val = val * 10 + d;
    }
    x = neg ? -val : val;
    return true;
}

struct LCA {
    int n = 0;
    int root = 1;
    int LOG = 0;
    vector<vector<int>> up;
    vector<int> depth;
    vector<vector<int>> g;

    LCA() = default;

    LCA(int n_, const vector<vector<int>>& g_, int root_) : n(n_), root(root_), g(g_) {
        LOG = 1;
        while ((1 << LOG) <= n) LOG++;
        up.assign(LOG, vector<int>(n + 1, 0));
        depth.assign(n + 1, 0);

        vector<int> parent(n + 1, 0);
        vector<int> vis(n + 1, 0);
        queue<int> q;
        q.push(root);
        vis[root] = 1;
        parent[root] = root;
        depth[root] = 0;

        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int v : g[u]) {
                if (vis[v]) continue;
                vis[v] = 1;
                parent[v] = u;
                depth[v] = depth[u] + 1;
                q.push(v);
            }
        }

        for (int v = 1; v <= n; v++) {
            if (!vis[v]) {

                parent[v] = v;
                depth[v] = 0;
            }
            up[0][v] = parent[v];
        }
        for (int k = 1; k < LOG; k++) {
            for (int v = 1; v <= n; v++) {
                up[k][v] = up[k - 1][ up[k - 1][v] ];
            }
        }
    }

    int lift(int v, int dist) const {
        for (int k = 0; k < LOG; k++) {
            if (dist & (1 << k)) v = up[k][v];
        }
        return v;
    }

    int lca(int a, int b) const {
        if (a < 1 || a > n || b < 1 || b > n) return 0;
        if (depth[a] < depth[b]) swap(a, b);
        a = lift(a, depth[a] - depth[b]);
        if (a == b) return a;
        for (int k = LOG - 1; k >= 0; k--) {
            if (up[k][a] != up[k][b]) {
                a = up[k][a];
                b = up[k][b];
            }
        }
        return up[0][a];
    }
};

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    int n = inf.readInt(2, 1000, "n");
    vector<pair<int,int>> edges;
    edges.reserve(max(0, n - 1));
    vector<vector<int>> g(n + 1);

    for (int i = 0; i < n - 1; i++) {
        int x = inf.readInt(1, n, "x_i");
        int y = inf.readInt(1, n, "y_i");
        if (x == y) finish(_fail, "Invalid hidden input: self-loop");
        edges.push_back({x, y});
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int root = inf.readInt(1, n, "r");

    query_limit = n / 2;
    log_metrics();

    const long long hard_cap = max(200000LL, 10LL * query_limit);

    cout << n << "\n";
    for (auto [u, v] : edges) cout << u << " " << v << "\n";
    cout.flush();

    LCA solver(n, g, root);

    while (true) {
        string cmd;
        if (!(cin >> cmd)) finish(_pe, "Unexpected EOF (no final answer)");

        if (cmd == "?") {
            long long u_ll, v_ll;
            if (!readIntFromCin(u_ll) || !readIntFromCin(v_ll)) {
                finish(_pe, "Malformed query: expected '? u v'");
            }
            if (u_ll < 1 || u_ll > n || v_ll < 1 || v_ll > n) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Invalid query vertices out of range");
            }

            queries++;
            if (queries > hard_cap) {
                finish(_pe, "Hard cap exceeded (too many queries)");
            }

            int u = (int)u_ll;
            int v = (int)v_ll;
            int w = solver.lca(u, v);
            if (w <= 0) {
                cout << -1 << "\n";
                cout.flush();
                finish(_wa, "Internal error computing LCA");
            }
            cout << w << "\n";
            cout.flush();
        } else if (cmd == "!") {
            long long ans_ll;
            if (!readIntFromCin(ans_ll)) finish(_pe, "Malformed answer: expected '! r'");
            if (ans_ll < 1 || ans_ll > n) finish(_wa, "Answer out of range");

            int ans = (int)ans_ll;
            if (ans == root) finish(_ok, "OK");
            finish(_wa, "Wrong root");
        } else {
            finish(_pe, "Unknown command (expected '?' or '!')");
        }
    }
}

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static vector<pair<int,int>> makePath(int n) {
    vector<pair<int,int>> e;
    e.reserve(max(0, n - 1));
    for (int i = 1; i < n; i++) e.push_back({i, i + 1});
    return e;
}

static vector<pair<int,int>> makeStar(int n, int center = 1) {
    vector<pair<int,int>> e;
    e.reserve(max(0, n - 1));
    for (int i = 1; i <= n; i++) if (i != center) e.push_back({center, i});
    return e;
}

static vector<pair<int,int>> makeBinaryHeap(int n) {
    vector<pair<int,int>> e;
    e.reserve(max(0, n - 1));
    for (int i = 2; i <= n; i++) e.push_back({i / 2, i});
    return e;
}

static vector<pair<int,int>> makeBroom(int n, int spineLen) {
    spineLen = max(2, min(spineLen, n));
    vector<pair<int,int>> e;
    e.reserve(max(0, n - 1));
    for (int i = 1; i < spineLen; i++) e.push_back({i, i + 1});
    for (int v = spineLen + 1; v <= n; v++) e.push_back({spineLen, v});
    return e;
}

static vector<pair<int,int>> makeCaterpillar(int n, int spineLen) {
    spineLen = max(2, min(spineLen, n));
    vector<pair<int,int>> e;
    e.reserve(max(0, n - 1));
    for (int i = 1; i < spineLen; i++) e.push_back({i, i + 1});
    for (int v = spineLen + 1; v <= n; v++) {
        int attach = rnd.next(1, spineLen);
        e.push_back({attach, v});
    }
    return e;
}

static vector<pair<int,int>> makeTwoHubs(int n, int hubCount) {
    hubCount = max(2, min(hubCount, max(2, n)));
    vector<int> hubs;
    hubs.reserve(hubCount);
    for (int i = 1; i <= hubCount; i++) hubs.push_back(i);

    vector<pair<int,int>> e;
    e.reserve(max(0, n - 1));

    for (int i = 2; i <= hubCount; i++) e.push_back({1, i});

    for (int v = hubCount + 1; v <= n; v++) {
        int bias = rnd.next(1, 100);
        int parent;
        if (bias <= 70) {
            parent = hubs[rnd.next(0, (int)hubs.size() - 1)];
        } else {
            parent = rnd.next(1, v - 1);
        }
        e.push_back({parent, v});
    }
    return e;
}

static vector<pair<int,int>> makeRecursiveRandom(int n) {
    vector<pair<int,int>> e;
    e.reserve(max(0, n - 1));
    for (int v = 2; v <= n; v++) {
        int parent;
        int roll = rnd.next(1, 100);
        if (roll <= 60) {
            parent = rnd.next(1, max(1, v - 1));
        } else if (roll <= 85) {
            parent = max(1, v - 1);
        } else {
            parent = 1;
        }
        e.push_back({parent, v});
    }
    return e;
}

static vector<vector<int>> buildAdj(int n, const vector<pair<int,int>>& edges) {
    vector<vector<int>> g(n + 1);
    for (auto [u, v] : edges) {
        g[u].push_back(v);
        g[v].push_back(u);
    }
    return g;
}

static int farthestFrom(int start, const vector<vector<int>>& g, vector<int>* parentOut = nullptr) {
    int n = (int)g.size() - 1;
    vector<int> dist(n + 1, -1), parent(n + 1, -1);
    queue<int> q;
    q.push(start);
    dist[start] = 0;
    parent[start] = 0;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int v : g[u]) if (dist[v] == -1) {
            dist[v] = dist[u] + 1;
            parent[v] = u;
            q.push(v);
        }
    }
    int best = start;
    for (int i = 1; i <= n; i++) {
        if (dist[i] > dist[best]) best = i;
    }
    if (parentOut) *parentOut = parent;
    return best;
}

static int pickAdversarialRoot(int n, const vector<pair<int,int>>& edges, long long seed) {
    auto g = buildAdj(n, edges);
    int a = farthestFrom(1, g);
    vector<int> parent;
    int b = farthestFrom(a, g, &parent);
    (void)parent;
    if (seed % 2 == 0) return a;
    return b;
}

static vector<int> makePermutation(int n) {
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++) p[i] = i;
    for (int i = 1; i <= n; i++) {
        int j = rnd.next(i, n);
        swap(p[i], p[j]);
    }
    return p;
}

int main(int argc, char** argv) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int maxn = opt<int>("n", 1000);
    int permuteLabels = opt<int>("permute", 1);

    long long seed = 1;
    if (argc >= 2) seed = atoll(argv[1]);

    int n;
    vector<pair<int,int>> edges;
    int root = 1;

    if (seed == 1) {
        n = 2;
        edges = {{1, 2}};
        root = 1;
        permuteLabels = 0;
    } else if (seed == 2) {
        n = min(1000, maxn);
        edges = makePath(n);
        root = 1;
        permuteLabels = 0;
    } else if (seed == 3) {
        n = min(1000, maxn);
        edges = makeBinaryHeap(n);
        root = n;
        permuteLabels = 0;
    } else {
        int hi = min(1000, maxn);
        int lo = max(2, hi - 30);
        n = rnd.next(lo, hi);

        string shape = opt<string>("shape", "auto");
        if (shape == "auto") {
            int pick = rnd.next(1, 100);
            if (pick <= 20) shape = "path";
            else if (pick <= 35) shape = "broom";
            else if (pick <= 55) shape = "caterpillar";
            else if (pick <= 75) shape = "twohubs";
            else if (pick <= 90) shape = "binary";
            else shape = "random";
        }

        if (shape == "path") {
            edges = makePath(n);
        } else if (shape == "star") {
            edges = makeStar(n, 1);
        } else if (shape == "binary") {
            edges = makeBinaryHeap(n);
        } else if (shape == "broom") {
            int spineLen = rnd.next(max(2, (int)(0.55 * n)), max(2, (int)(0.85 * n)));
            edges = makeBroom(n, spineLen);
        } else if (shape == "caterpillar") {
            int spineLen = rnd.next(max(2, (int)(0.35 * n)), max(2, (int)(0.65 * n)));
            edges = makeCaterpillar(n, spineLen);
        } else if (shape == "twohubs") {
            int hubs = rnd.next(2, min(25, n));
            edges = makeTwoHubs(n, hubs);
        } else {
            edges = makeRecursiveRandom(n);
        }

        root = pickAdversarialRoot(n, edges, seed);
    }

    if (permuteLabels && n >= 3) {
        vector<int> p = makePermutation(n);
        for (auto &e : edges) {
            e.first = p[e.first];
            e.second = p[e.second];
        }
        root = p[root];
    }

    cout << n << "\n";
    for (auto [u, v] : edges) {
        cout << u << " " << v << "\n";
    }

    if (mode == "non") {
        cout << root << "\n";
        return 0;
    }

    if (mode == "adp") {
        int k = n;
        cout << k << "\n";
        for (int i = 1; i <= n; i++) {
            if (i > 1) cout << " ";
            cout << i;
        }
        cout << "\n";
        return 0;
    }

    quitf(_fail, "Unknown --mode '%s' (expected 'non' or 'adp')", mode.c_str());
}


E. The penguin's game

Pay attention: this problem is interactive.

Penguin Xoriy came up with a new game recently. He has *n* icicles numbered from 1 to *n*. Each icicle has a temperature — an integer from 1 to 109. Exactly two of these icicles are special: their temperature is *y*, while a temperature of all the others is *x* ≠ *y*. You have to find those special icicles. You can choose a non-empty subset of icicles and ask the penguin what is the bitwise exclusive OR (XOR) of the temperatures of the icicles in this subset. Note that you can't ask more than 19 questions.

You are to find the special icicles.

Input

The first line contains three integers *n*, *x*, *y* (2 ≤ *n* ≤ 1000, 1 ≤ *x*, *y* ≤ 109, *x* ≠ *y*) — the number of icicles, the temperature of non-special icicles and the temperature of the special icicles.

Output

To give your answer to the penguin you have to print character "!" (without quotes), then print two integers *p*1, *p*2 (*p*1 < *p*2) — the indexes of the special icicles in ascending order. Note that "!" and *p*1 should be separated by a space; the indexes should be separated by a space too. After you gave the answer your program should terminate immediately.

Interaction

To ask a question print character "?" (without quotes), an integer *c* (1 ≤ *c* ≤ *n*), and *c* distinct integers *p*1, *p*2,..., *p**c* (1 ≤ *p**i* ≤ *n*) — the indexes of icicles that you want to know about. Note that "?" and *c* should be separated by a space; the indexes should be separated by a space too.

After you asked the question, read a single integer — the answer.

Note that you can't ask more than 19 questions. If you ask more than 19 questions or at least one incorrect question, your solution will get "Wrong answer".

If at some moment your program reads  - 1 as an answer, it should immediately exit (for example, by calling exit(0)). You will get "Wrong answer" in this case, it means that you asked more than 19 questions, or asked an invalid question. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including for the final answer.

To flush you can use (just after printing):

* fflush(stdout) in C++;
* System.out.flush() in Java;
* stdout.flush() in Python;
* flush(output) in Pascal;
* For other languages see the documentation.

Example

Input

```
4 2 1
2
1
1
```

Output

```? 3 1 2 3? 1 1? 1 3! 1 3
```

Note

The answer for the first question is![](https://espresso.codeforces.com/b32d8d96beb0d2be8d8a600f458c8cf2e2e28c54.png).

The answer for the second and the third questions is 1, therefore, special icicles are indexes 1 and 3.

You can read more about bitwise XOR operation here: [link omitted].

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;
static long long query_limit = 19;
static const long long hard_cap = 20000;

static void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char** argv) {

    registerInteraction(argc, argv);
    atexit(log_metrics);

    int n = inf.readInt(2, 1000, "n");
    long long x = inf.readLong(1LL, 1000000000LL, "x");
    long long y = inf.readLong(1LL, 1000000000LL, "y");

    if (x == y) {
        quitf(_fail, "Test case invalid: x (%lld) must not equal y (%lld)", x, y);
    }

    int p1 = inf.readInt(1, n, "p1");
    int p2 = inf.readInt(1, n, "p2");

    if (p1 == p2) {
        quitf(_fail, "Test case invalid: hidden indices p1 and p2 must be distinct");
    }

    if (p1 > p2) swap(p1, p2);

    cout << n << " " << x << " " << y << endl;

    log_metrics();

    string token;
    while (cin >> token) {
        if (token == "!") {

            int a1, a2;
            if (!(cin >> a1 >> a2)) {
                finish(_wa, "Failed to read answer indices after '!'");
            }

            if (a1 >= a2) {
                finish(_wa, "Answer indices must be distinct and in strictly ascending order");
            }

            if (a1 == p1 && a2 == p2) {
                finish(_ok, "Correct answer");
            } else {
                finish(_wa, format("Wrong answer: expected %d %d, found %d %d", p1, p2, a1, a2));
            }
            return 0;
        }

        int c = 0;
        if (token == "?") {
            if (!(cin >> c)) {
                finish(_wa, "Failed to read query size 'c' after '?'");
            }
        } else {

            try {
                size_t pos = 0;
                c = stoi(token, &pos);
                if (pos != token.size()) {
                    finish(_wa, "Invalid token encountered: " + token);
                }
            } catch (...) {
                finish(_wa, "Invalid token (not an integer): " + token);
            }
        }

        if (c < 1 || c > n) {
            finish(_wa, format("Query size %d out of range [1, %d]", c, n));
        }

        int special_in_query = 0;
        set<int> distinct_check;

        for (int i = 0; i < c; i++) {
            int idx;
            if (!(cin >> idx)) {
                finish(_wa, "Failed to read index for query");
            }
            if (idx < 1 || idx > n) {
                finish(_wa, format("Query index %d out of range [1, %d]", idx, n));
            }
            if (distinct_check.count(idx)) {
                finish(_wa, format("Duplicate index %d in query", idx));
            }
            distinct_check.insert(idx);

            if (idx == p1 || idx == p2) {
                special_in_query++;
            }
        }

        long long response = 0;
        if ((c - special_in_query) % 2 != 0) response ^= x;
        if (special_in_query % 2 != 0) response ^= y;

        queries++;
        log_metrics();

        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded");
        }

        cout << response << endl;
    }

    finish(_wa, "Stream ended without final answer '!'");
    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;

static long long query_limit = 19;

static const long long HARD_CAP = 200000;

static void log_metrics() {

    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

int main(int argc, char** argv) {

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int n = inf.readInt();
    long long x = inf.readLong();
    long long y = inf.readLong();

    cout << n << " " << x << " " << y << endl;

    vector<pair<int, int>> candidates;
    long long num_pairs = (long long)n * (n - 1) / 2;
    candidates.reserve(num_pairs);
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            candidates.push_back({i, j});
        }
    }

    log_metrics();

    while (true) {

        string type;
        if (!(cin >> type)) {
            finish(_pe, "Unexpected end of output");
        }

        if (type == "!") {

            int ans1, ans2;
            if (!(cin >> ans1 >> ans2)) {
                finish(_pe, "Invalid format for final answer");
            }
            if (ans1 > ans2) swap(ans1, ans2);

            bool found_ans = false;
            bool found_other = false;
            pair<int, int> counter_example = {-1, -1};

            for (const auto& p : candidates) {
                if (p.first == ans1 && p.second == ans2) {
                    found_ans = true;
                } else {
                    found_other = true;
                    counter_example = p;

                    break;
                }
            }

            if (found_other) {

                finish(_wa, "found " + to_string(ans1) + " " + to_string(ans2) +
                            ", expected " + to_string(counter_example.first) + " " + to_string(counter_example.second));
            } else if (found_ans) {

                finish(_ok, "Correct");
            } else {

                if (candidates.empty()) finish(_pe, "Internal error: feasible set is empty");
                counter_example = candidates[0];
                finish(_wa, "found " + to_string(ans1) + " " + to_string(ans2) +
                            ", expected " + to_string(counter_example.first) + " " + to_string(counter_example.second));
            }
            return 0;

        } else if (type == "?") {

            queries++;

            if (queries % 5 == 0) log_metrics();

            if (queries > HARD_CAP) {
                finish(_pe, "Hard query limit exceeded");
            }

            int k;
            if (!(cin >> k)) finish(_pe, "Invalid format for query size");
            if (k < 1 || k > n) finish(_wa, "Query size out of range");

            vector<bool> in_query(n + 1, false);
            for (int i = 0; i < k; ++i) {
                int idx;
                cin >> idx;
                if (idx < 1 || idx > n) finish(_wa, "Index out of range");
                if (in_query[idx]) finish(_wa, "Duplicate index in query");
                in_query[idx] = true;
            }

            vector<pair<int, int>> s_even, s_odd;
            s_even.reserve(candidates.size());
            s_odd.reserve(candidates.size());

            for (const auto& p : candidates) {
                int count = (in_query[p.first] ? 1 : 0) + (in_query[p.second] ? 1 : 0);

                if (count == 1) {
                    s_odd.push_back(p);
                } else {

                    s_even.push_back(p);
                }
            }

            long long response;

            if (s_even.size() >= s_odd.size()) {
                candidates = move(s_even);

                if (k % 2 != 0) response = x;
                else response = 0;
            } else {
                candidates = move(s_odd);

                long long term_x = ((k - 1) % 2 != 0) ? x : 0;
                response = term_x ^ y;
            }

            if (candidates.empty()) {
                finish(_pe, "Internal error: feasible set became empty");
            }

            cout << response << endl;

        } else {
            finish(_pe, "Invalid query type");
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int n = opt<int>("n", -1);
    long long x = opt<long long>("x", -1);
    long long y = opt<long long>("y", -1);

    int seed_val = atoi(argv[1]);

    if (n == -1) {
        if (seed_val == 1) n = 2;
        else if (seed_val == 2) n = 3;
        else if (seed_val == 3) n = 1000;
        else n = rnd.next(2, 1000);
    }

    if (x == -1) {

        if (rnd.next(5) == 0) x = rnd.next(1, 100);
        else x = rnd.next(1, 1000000000);
    }

    if (y == -1) {
        int t = rnd.next(10);
        if (t < 3) {

            bool found = false;
            for (int k = 0; k < 10; ++k) {
                int bit = rnd.next(0, 29);
                long long cand = x ^ (1LL << bit);
                if (cand >= 1 && cand <= 1000000000LL) {
                    y = cand;
                    found = true;
                    break;
                }
            }
            if (!found) {
                do { y = rnd.next(1, 1000000000); } while (y == x);
            }
        } else {

            do { y = rnd.next(1, 1000000000); } while (y == x);
        }
    }

    if (x == y) {
        if (y < 1000000000) y++; else y--;
    }

    cout << n << " " << x << " " << y << endl;

    if (mode == "non") {

        int p1, p2;

        if (n == 2) {

            p1 = 1; p2 = 2;
        } else {

            bool fixed = false;

            if (seed_val == 2 && n == 3) { p1 = 1; p2 = 3; fixed = true; }
            if (seed_val == 3 && n == 1000) { p1 = 1; p2 = 1000; fixed = true; }

            if (!fixed) {
                int type = rnd.next(100);
                if (type < 15) {

                    p1 = rnd.next(1, n - 1);
                    p2 = p1 + 1;
                } else if (type < 30) {

                    p1 = 1; p2 = n;
                } else if (type < 60) {

                    bool found = false;
                    for (int k = 0; k < 20; ++k) {
                        p1 = rnd.next(1, n);
                        int bit = rnd.next(0, 9);
                        int cand = p1 ^ (1 << bit);
                        if (cand >= 1 && cand <= n && cand != p1) {
                            p2 = cand;
                            found = true;
                            break;
                        }
                    }
                    if (!found) {

                        p1 = rnd.next(1, n);
                        do { p2 = rnd.next(1, n); } while (p1 == p2);
                    }
                } else {

                    p1 = rnd.next(1, n);
                    do { p2 = rnd.next(1, n); } while (p1 == p2);
                }
            }
        }

        if (p1 > p2) swap(p1, p2);
        cout << p1 << " " << p2 << endl;
    }

    return 0;
}