This is an interactive problem.

Vasya and Vitya play a game. Vasya thought of two integers $a$ and $b$ from $1$ to $n$ and Vitya tries to guess them. Each round he tells Vasya two numbers $x$ and $y$ from $1$ to $n$. If both $x=a$ and $y=b$ then Vitya wins. Else Vasya must say one of the three phrases:

1. $x$ is less than $a$;
2. $y$ is less than $b$;
3. $x$ is greater than $a$ or $y$ is greater than $b$.

Vasya can't lie, but if multiple phrases are true, he may choose any of them. For example, if Vasya thought of numbers $2$ and $4$, then he answers with the phrase $3$ to a query $(3, 4)$, and he can answer with the phrase $1$ or phrase $3$ to a query $(1, 5)$.

Help Vitya win in no more than $600$ rounds.

Input

The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the upper limit of the numbers.

Interaction

First, you need to read the number $n$, after that you can make queries.

To make a query, print two integers: $x$ and $y$ ($1 \leq x, y \leq n$), then flush the output.

After each query, read a single integer $ans$ ($0 \leq ans \leq 3$).

If $ans > 0$, then it is the number of the phrase said by Vasya.

If $ans = 0$, it means that you win and your program should terminate.

If you make more than $600$ queries or make an incorrect query, you will get Wrong Answer.

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

To flush you need to do the following right after printing a query and a line end:

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

Example

Input

```
5
3
3
2
1
0
```

Output

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

Note

Let's analyze the sample test. The chosen numbers are $2$ and $4$. The interactor was given two instructions.

For the query $(4, 3)$, it can return $2$ or $3$. Out of the two instructions the second one is chosen, so the interactor returns $a^{23}_2=3$.

For the query $(3, 4)$, it can return only $3$.

For the query $(3, 3)$, it can return $2$ or $3$. Out of the two instructions the first one is chosen (since in case of equal values, the least number is preferred), so the interactor returns $a^{23}_1=2$.

For the query $(1, 5)$, it can return $1$ or $3$. Out of the two instructions the first one is chosen, so the interactor returns $a^{13}_1=1$.

In the fifth query $(2, 4)$, the numbers are guessed correctly, the player wins.

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

using namespace std;

static long long queries = 0;
static const long long query_limit = 600;

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

#define FINISH(verdict, ...) { log_metrics(); quitf(verdict, __VA_ARGS__); }

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    long long n = inf.readLong();
    long long a = inf.readLong();
    long long b = inf.readLong();

    cout << n << endl;

    log_metrics();

    while (true) {

        string token;
        if (!(cin >> token)) {

            FINISH(_wa, "Unexpected end of stream (solution exited?)");
        }

        if (token == "?" || token == "!") {
            if (!(cin >> token)) {
                FINISH(_wa, "Unexpected end of stream after prefix");
            }
        }

        long long x;
        try {
            x = stoll(token);
        } catch (...) {
            FINISH(_wa, "Invalid integer format for x: %s", token.c_str());
        }

        long long y;
        if (!(cin >> y)) {
            FINISH(_wa, "Unexpected end of stream before y");
        }

        queries++;

        if (queries > query_limit) {
            FINISH(_wa, "Query limit exceeded (%lld > %lld)", queries, query_limit);
        }

        if (x < 1 || x > n || y < 1 || y > n) {
            FINISH(_wa, "Coordinates out of bounds: (%lld, %lld), n=%lld", x, y, n);
        }

        if (x == a && y == b) {
            cout << 0 << endl;
            FINISH(_ok, "Guessed correctly in %lld queries", queries);
        }

        vector<int> valid;
        if (x < a) valid.push_back(1);
        if (y < b) valid.push_back(2);
        if (x > a || y > b) valid.push_back(3);

        if (valid.empty()) {
            FINISH(_fail, "Internal logic error: no valid response for guess (%lld, %lld) with target (%lld, %lld)", x, y, a, b);
        }

        int response = valid[rnd.next(valid.size())];

        cout << response << endl;
    }

    return 0;
}

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

using namespace std;

typedef __int128_t int128;

struct Rect {
    long long x1, x2, y1, y2;
    int128 area() const {
        if (x1 > x2 || y1 > y2) return 0;
        return (int128)(x2 - x1 + 1) * (int128)(y2 - y1 + 1);
    }
};

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

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());
}

int128 total_area(const vector<Rect>& rects) {
    int128 sum = 0;
    for (const auto& r : rects) sum += r.area();
    return sum;
}

vector<Rect> apply_move(const vector<Rect>& current, int type, long long x, long long y) {
    vector<Rect> next_rects;
    if (type == 1) {

        for (auto r : current) {
            r.x1 = max(r.x1, x + 1);
            if (r.x1 <= r.x2 && r.y1 <= r.y2) next_rects.push_back(r);
        }
    } else if (type == 2) {

        for (auto r : current) {
            r.y1 = max(r.y1, y + 1);
            if (r.x1 <= r.x2 && r.y1 <= r.y2) next_rects.push_back(r);
        }
    } else if (type == 3) {

        for (auto r : current) {
            long long ix1 = max(r.x1, x);
            long long ix2 = r.x2;
            long long iy1 = max(r.y1, y);
            long long iy2 = r.y2;

            if (ix1 > ix2 || iy1 > iy2) {
                next_rects.push_back(r);
            } else {

                long long rx1 = r.x1;
                long long rx2 = min(r.x2, x - 1);
                if (rx1 <= rx2) {
                    next_rects.push_back({rx1, rx2, r.y1, r.y2});
                }

                long long bx1 = max(r.x1, x);
                long long bx2 = r.x2;
                long long by1 = r.y1;
                long long by2 = min(r.y2, y - 1);
                if (bx1 <= bx2 && by1 <= by2) {
                    next_rects.push_back({bx1, bx2, by1, by2});
                }
            }
        }
    }
    return next_rects;
}

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

    long long n = inf.readLong();

    cout << n << endl;

    vector<Rect> feasible;
    feasible.push_back({1, n, 1, n});

    int hard_cap = 2000;

    while (true) {
        long long x, y;

        if (!(cin >> x >> y)) {
            finish(_wa, "Unexpected EOF or invalid query format");
        }

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

        if (x < 1 || x > n || y < 1 || y > n) {
            finish(_wa, format("Query (%lld, %lld) out of range [1, %lld]", x, y, n));
        }

        vector<Rect> f1 = apply_move(feasible, 1, x, y);
        int128 a1 = total_area(f1);

        vector<Rect> f2 = apply_move(feasible, 2, x, y);
        int128 a2 = total_area(f2);

        vector<Rect> f3 = apply_move(feasible, 3, x, y);
        int128 a3 = total_area(f3);

        int128 max_a = a1;
        int ans = 1;

        if (a2 > max_a) {
            max_a = a2;
            ans = 2;
        }

        if (a3 > max_a) {
            max_a = a3;
            ans = 3;
        } else if (a3 == max_a && max_a > 0) {

            ans = 3;
        }

        if (max_a == 0) {

            cout << 0 << endl;
            finish(_ok, format("Guessed correctly in %lld queries", queries));
        } else {

            if (ans == 1) feasible = f1;
            else if (ans == 2) feasible = f2;
            else feasible = f3;

            cout << ans << endl;
        }
    }

    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 n = opt<long long>("n", -1);

    int seed = atoi(argv[1]);

    if (n == -1) {
        if (seed == 1) n = 5;
        else if (seed == 2) n = 3;
        else if (seed == 3) n = 1;
        else if (seed == 4) n = 1000000000000000000LL;
        else if (seed == 5) n = 999999999999999999LL;
        else {

            if (rnd.next(2)) {
                n = rnd.next(1LL, 1000000000000000000LL);
            } else {
                int p = rnd.next(0, 18);
                long long lower = 1;
                for (int i = 0; i < p; ++i) lower *= 10;
                long long upper = lower * 10 - 1;
                if (p == 18) upper = 1000000000000000000LL;
                if (upper > 1000000000000000000LL) upper = 1000000000000000000LL;
                n = rnd.next(lower, upper);
            }
        }
    }

    if (mode == "non") {
        long long a, b;

        if (seed == 1 && n == 5) {
            a = 2; b = 4;
        } else if (seed == 2 && n == 3) {
            a = 3; b = 1;
        } else if (seed == 3 && n == 1) {
            a = 1; b = 1;
        } else {

            int strategy = rnd.next(10);
            if (strategy == 0) {

                a = 1; b = 1;
            } else if (strategy == 1) {

                a = n; b = n;
            } else if (strategy == 2) {

                a = 1; b = n;
            } else if (strategy == 3) {

                a = n; b = 1;
            } else if (strategy < 6) {

                a = rnd.next(1LL, n);
                b = rnd.next(1LL, n);
            } else if (strategy < 8) {

                a = rnd.next(1LL, n);
                b = a + rnd.next(-100LL, 100LL);
                b = max(1LL, min(n, b));
            } else {

                a = rnd.next(1LL, n);
                b = n - a + rnd.next(-100LL, 100LL);
                b = max(1LL, min(n, b));
            }
        }
        cout << n << "\n" << a << " " << b << endl;
    }
    else if (mode == "adp") {

        cout << n << endl;
    }
    else {
        quitf(_fail, "Unknown mode: %s", mode.c_str());
    }

    return 0;
}


This is an interactive problem.

You are given an array $x_1, \ldots, x_n$ of integers from $1$ to $n$. The jury also has a fixed but hidden array $y_1, \ldots, y_n$ of integers from $1$ to $n$. The elements of array $y$ are unknown to you. Additionally, it is known that for all $i$, $x_i \neq y_i$, and all pairs $(x_i, y_i)$ are distinct.

The jury has secretly thought of one of two objects, and you need to determine which one it is:

* Object A: A directed graph with $n$ vertices numbered from $1$ to $n$, and with $n$ edges of the form $x_i \to y_i$.
* Object B: $n$ points on a coordinate plane. The $i$-th point has coordinates $(x_i, y_i)$.

To guess which object the jury has thought of, you can make queries. In one query, you must specify two numbers $i, j$ $(1 \leq i, j \leq n, i \neq j)$. In response, you receive one number:

* If the jury has thought of Object A, you receive the length of the shortest path (in edges) from vertex $i$ to vertex $j$ in the graph, or $0$ if there is no path.
* If the jury has thought of Object B, you receive the Manhattan distance between points $i$ and $j$, that is $|x_i -x_j| + |y_i - y_j|$.

You have $2$ queries to determine which of the objects the jury has thought of.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

Interaction

The interaction begins with reading $n$ ($3 \leq n \leq 2 \cdot 10^5$) — the length of the arrays $x$ and $y$ at the start of each test case.

Next, read $n$ integers: $x_1, x_2, \ldots, x_n$ ($1 \leq x_i \leq n$) — the elements of array $x$.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.

The array $y_1, y_2, \ldots, y_n$ is fixed for each test case. In other words, the interactor is not adaptive.

It is guaranteed that $x_i \neq y_i$ for all $1 \leq i \leq n$, and all pairs $(x_i, y_i)$ are distinct.

To make a query, output "? $i$ $j$" (without quotes, $1 \le i, j \le n, i \neq j$). Then you must read the response to the query, which is a non-negative integer.

To give an answer, output "! A" if Object A is hidden or "! B" if Object B is hidden (without quotes). Note that printing the answer does not count as one of the $2$ queries.

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict. If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will reveive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream. Note that if the query is correct, the response will never be $-1$.

Example

Input

```
2
3
2 2 3

1

0

5
5 1 4 2 3

4

4
```

Output

```
? 2 3

? 1 2

! A

? 1 5

? 5 1

! B
```

Note

In the first test case, $x = [2,2,3]$, $y = [1,3,1]$ and Object A is guessed.

In the second test case, $x = [5,1,4,2,3]$, $y = [3,3,2,4,1]$ and Object B is guessed.

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

static long long queries = 0;
static long long query_limit = 0;
static long long hard_cap = 200000;

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 readToken(string& tok) {
    tok.clear();
    if (!(cin >> tok)) return false;
    return true;
}

static bool parsePosIntInRange(const string& s, int& out, int lo, int hi) {
    if (s.empty()) return false;
    long long val = 0;
    for (char c : s) {
        if (c < '0' || c > '9') return false;
        val = val * 10 + (c - '0');
        if (val > (long long)hi) return false;
    }
    if (val < lo || val > hi) return false;
    out = (int)val;
    return true;
}

static void sendMinusOne() {
    cout << -1 << endl;
}

static int shortestPathDirected(int n, const vector<vector<int>>& adj, int s, int t) {
    if (s == t) return 0;
    vector<int> dist(n + 1, -1);
    deque<int> q;
    dist[s] = 0;
    q.push_back(s);
    while (!q.empty()) {
        int u = q.front();
        q.pop_front();
        int nd = dist[u] + 1;
        for (int v : adj[u]) {
            if (dist[v] != -1) continue;
            dist[v] = nd;
            if (v == t) return nd;
            q.push_back(v);
        }
    }
    return 0;
}

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

    int t = 0;
    try {
        t = inf.readInt();
    } catch (...) {
        query_limit = 0;
        log_metrics();
        finish(_pe, "Failed to read t from inf");
    }
    if (t < 1 || t > 1000) {
        query_limit = 0;
        log_metrics();
        finish(_pe, "Invalid t in inf");
    }

    query_limit = 2LL * t;
    hard_cap = max(200000LL, 10LL * query_limit);
    log_metrics();

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

    for (int tc = 1; tc <= t; tc++) {
        int n = inf.readInt();
        if (n < 3 || n > 200000) finish(_pe, "Invalid n in inf");

        vector<int> x(n + 1), y(n + 1);
        for (int i = 1; i <= n; i++) {
            x[i] = inf.readInt(1, n);
        }
        for (int i = 1; i <= n; i++) {
            y[i] = inf.readInt(1, n);
        }

        string objTok = inf.readToken();
        if (objTok.empty()) finish(_pe, "Missing object token in inf");
        char obj = (char)toupper((unsigned char)objTok[0]);
        if (obj != 'A' && obj != 'B') finish(_pe, "Invalid object token in inf");

        vector<vector<int>> adj;
        if (obj == 'A') {
            adj.assign(n + 1, {});
            for (int i = 1; i <= n; i++) adj[x[i]].push_back(y[i]);
        }

        cout << n << '\n';
        for (int i = 1; i <= n; i++) {
            if (i > 1) cout << ' ';
            cout << x[i];
        }
        cout << '\n';
        cout.flush();

        bool answered = false;
        while (!answered) {
            string cmd;
            if (!readToken(cmd)) finish(_pe, "EOF from contestant before answering");

            if (cmd == "?") {
                string si, sj;
                if (!readToken(si) || !readToken(sj)) {
                    sendMinusOne();
                    cout.flush();
                    finish(_pe, "Malformed query: missing i/j");
                }

                int i = 0, j = 0;
                if (!parsePosIntInRange(si, i, 1, n) || !parsePosIntInRange(sj, j, 1, n) || i == j) {
                    sendMinusOne();
                    cout.flush();
                    finish(_pe, "Invalid query indices");
                }

                queries++;
                if (queries > hard_cap) {
                    sendMinusOne();
                    cout.flush();
                    finish(_pe, "Hard cap exceeded");
                }

                long long ans = 0;
                if (obj == 'B') {
                    ans = llabs((long long)x[i] - x[j]) + llabs((long long)y[i] - y[j]);
                } else {
                    ans = shortestPathDirected(n, adj, i, j);
                }

                cout << ans << '\n';
                cout.flush();
            } else if (cmd == "!") {
                string guessTok;
                if (!readToken(guessTok) || guessTok.empty()) {
                    sendMinusOne();
                    cout.flush();
                    finish(_pe, "Malformed answer: missing A/B");
                }
                char g = (char)toupper((unsigned char)guessTok[0]);
                if (g != 'A' && g != 'B') {
                    sendMinusOne();
                    cout.flush();
                    finish(_pe, "Malformed answer: not A/B");
                }
                if (g != obj) finish(_wa, "Wrong object guessed");
                answered = true;
            } else {
                sendMinusOne();
                cout.flush();
                finish(_pe, "Unexpected command token");
            }
        }
    }

    string extra;
    if (readToken(extra)) finish(_pe, "Extra output after finishing all testcases");
    finish(_ok, "OK");
}

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

static vector<int> randomPermutation(int n) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    for (int i = 0; i < n; i++) {
        int j = rnd.next(i, n - 1);
        swap(p[i], p[j]);
    }
    return p;
}

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

    string mode = opt<string>("mode", "non");
    int nDefault = opt<int>("n", 200000);
    string objOpt = opt<string>("obj", "");

    int seed = 1;
    if (argc >= 2) seed = atoi(argv[1]);

    char obj;
    if (!objOpt.empty()) {
        obj = objOpt[0];
        if (obj != 'A' && obj != 'B') obj = 'A';
    } else {
        obj = (seed % 2 ? 'A' : 'B');
    }

    int n = nDefault;
    if (n < 3) n = 3;
    if (n > 200000) n = 200000;

    vector<int> x, y;

    if (seed == 1) {
        n = 3;
        x = {1, 2, 3};
        y = {2, 3, 1};
        obj = 'A';
    } else if (seed == 2) {
        n = 3;
        x = {1, 1, 2};
        y = {2, 3, 3};
        obj = 'A';
    } else if (seed == 3) {
        n = 5;
        x = {1, 2, 3, 4, 5};
        y = {2, 1, 4, 5, 3};
        obj = 'B';
    } else {

        n = nDefault;
        if (n < 3) n = 3;
        if (n > 200000) n = 200000;

        x = randomPermutation(n);

        vector<int> cycle = randomPermutation(n);
        vector<int> f(n + 1, 0);
        for (int i = 0; i < n; i++) {
            int u = cycle[i];
            int v = cycle[(i + 1) % n];
            f[u] = v;
        }

        y.resize(n);
        for (int i = 0; i < n; i++) {
            y[i] = f[x[i]];
        }
    }

    cout << 1 << "\n";
    cout << n << "\n";
    for (int i = 0; i < n; i++) {
        if (i) cout << ' ';
        cout << x[i];
    }
    cout << "\n";

    if (mode == "non") {
        for (int i = 0; i < n; i++) {
            if (i) cout << ' ';
            cout << y[i];
        }
        cout << "\n";
        cout << obj << "\n";
    } else if (mode == "adp") {

        cout << obj << "\n";
    } else {

        for (int i = 0; i < n; i++) {
            if (i) cout << ' ';
            cout << y[i];
        }
        cout << "\n";
        cout << obj << "\n";
    }

    return 0;
}


Linda likes to change her hair color from time to time, and would be pleased if her boyfriend Archie would notice the difference between the previous and the new color. Archie always comments on Linda's hair color if and only if he notices a difference — so Linda always knows whether Archie has spotted the difference or not.

There is a new hair dye series in the market where all available colors are numbered by integers from $1$ to $N$ such that a smaller difference of the numerical values also means less visual difference.

Linda assumes that for these series there should be some critical color difference $C$ ($1 \le C \le N$) for which Archie will notice color difference between the current color $\mathrm{color}_{\mathrm{new}}$ and the previous color $\mathrm{color}_{\mathrm{prev}}$ if $\left|\mathrm{color}_{\mathrm{new}} - \mathrm{color}_{\mathrm{prev}}\right| \ge C$ and will not if $\left|\mathrm{color}_{\mathrm{new}} - \mathrm{color}_{\mathrm{prev}}\right| < C$.

Now she has bought $N$ sets of hair dye from the new series — one for each of the colors from $1$ to $N$, and is ready to set up an experiment. Linda will change her hair color on a regular basis and will observe Archie's reaction — whether he will notice the color change or not. Since for the proper dye each set should be used completely, each hair color can be obtained no more than once.

Before the experiment, Linda was using a dye from a different series which is not compatible with the new one, so for the clearness of the experiment Archie's reaction to the first used color is meaningless.

Her aim is to find the precise value of $C$ in a limited number of dyes. Write a program which finds the value of $C$ by experimenting with the given $N$ colors and observing Archie's reactions to color changes.

Interaction

This is an interactive task. In the beginning you are given a single integer $T$ ($1 \leq T \leq 100$), the number of cases in the test.

For each test case, the input first contains a single integer — the value of $N$ ($1 < N \le 10^{18}$). The value of $C$ is kept secret by the grading system.

Then your program should make queries writing output in the following format: "? $P$", where $P$ is an integer ($1 \le P \le N$) denoting the next color used. For each query the grading system gives an answer in the next line of the input. The answer is $1$ if Archie notices the color difference between the last two colors and $0$ otherwise. No two queries should have the same $P$ value.

When your program determines $C$, it should output its value in the following format: "= $C$". The grading system will not respond to this output and will proceed with the next test case.

Your program may use at most 64 queries "?" for each test case to find the correct value of $C$.

To establish proper communication between your program and the grading system, you should flush the output stream after each query.

\begin{array}{ll} \text{Language} & \text{Command} \\ \hline \text{C++} & \texttt{std::cout }\texttt{<}\texttt{<}\texttt{ std::endl;} \\ \text{Java} & \texttt{System.out.flush();} \\ \text{Python} & \texttt{sys.stdout.flush()} \end{array} Flush commands

Note that std::endl writes a newline and flushes the stream.

It is possible to receive an "Output isn't correct" outcome even after printing a correct answer, if task constraints were violated during the communication. Violating the communication protocol itself may result in an "Execution killed" outcome.

Submitting user tests requires specifying an input file with the testcase parameters. The format of the input file is "$T$" in the first line, and then "$N$ $C$" on a single line for each of the $T$ cases.

Scoring

Subtasks:

1. (9 points) $N \le 64$
2. (13 points) $N \le 125$
3. (21 points) $N \le 1000$
4. (24 points) $N \le 10^9$
5. (33 points) No further constraints.

Example

Input

```
1

7

1

1

0

0

1
```

Output

```
? 2

? 7

? 4

? 1

? 5

= 4
```

Note

Comments to the example input line by line:

1. $N = 7$.
2. Answer to the first query is meaningless (can also be $0$).
3. $C \leq 5$.
4. $3 < C \leq 5$. It would be wise to check difference $4$. However, this can not be done in the next query since $4 + 4 = 8$ and $4 - 4 = 0$ both are outside the allowed interval $1 \le P \le 7$.
5. $3 < C \leq 5$.
6. $3 < C \leq 4$. Therefore, $C = 4$.

#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 << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

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

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

static string readTokenOrPE(const string& ctx) {
    string t;
    if (!(cin >> t)) finish(_pe, "Unexpected EOF while reading " + ctx);
    return t;
}

static long long readLLOrPE(const string& ctx) {
    string s = readTokenOrPE(ctx);
    long long v;
    if (!parseLL_strict(s, v)) finish(_pe, "Expected integer for " + ctx);
    return v;
}

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

    const long long LIM = 1000000000000000000LL;

    int T = (int)inf.readInt(1, 100, "T");
    vector<long long> N(T), C(T);
    for (int tc = 0; tc < T; tc++) {
        N[tc] = inf.readLong(2, LIM, "N");
        C[tc] = inf.readLong(1, N[tc], "C");
    }

    query_limit = 64LL * T;
    log_metrics();

    cout << T << "\n";
    for (int tc = 0; tc < T; tc++) cout << N[tc] << "\n";
    cout.flush();

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

    for (int tc = 0; tc < T; tc++) {
        set<long long> used;
        bool hasPrev = false;
        long long prev = -1;

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

            string cmd = readTokenOrPE("command");
            long long val = -1;
            bool hasAttached = false;

            if (!cmd.empty() && (cmd[0] == '?' || cmd[0] == '=')) {
                if (cmd.size() > 1) {
                    string rest = cmd.substr(1);
                    if (!parseLL_strict(rest, val)) finish(_pe, "Invalid attached integer after command");
                    hasAttached = true;
                    cmd = string(1, cmd[0]);
                }
            }

            if (cmd == "?") {
                if (!hasAttached) val = readLLOrPE("P");
                long long P = val;

                if (P < 1 || P > N[tc]) finish(_pe, "Query P out of range");
                if (used.count(P)) finish(_pe, "Duplicate P in queries");
                used.insert(P);

                queries++;

                int ans = 0;
                if (!hasPrev) {
                    ans = 0;
                    hasPrev = true;
                    prev = P;
                } else {
                    long long diff = llabs(P - prev);
                    ans = (diff >= C[tc]) ? 1 : 0;
                    prev = P;
                }

                cout << ans << "\n";
                cout.flush();
            } else if (cmd == "=") {
                if (!hasAttached) val = readLLOrPE("answer C");
                long long guess = val;

                if (guess < 1 || guess > N[tc]) finish(_wa, "Answer C out of range");
                if (guess != C[tc]) finish(_wa, "Wrong answer");
                break;
            } else {
                finish(_pe, "Unknown command token");
            }
        }
    }

    {
        string extra;
        if (cin >> extra) finish(_pe, "Extra output after finishing all test cases");
    }

    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 parseLongLongStrict(const string& s, long long& out) {

    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;
    }
}

struct HiddenCase {
    long long N = 0;
    bool fixed = false;
    long long C = 0;
    long long lo = 0, hi = 0;
};

static inline long long absDiffLL(long long a, long long b) {
    return (a >= b) ? (a - b) : (b - a);
}

static int chooseAdaptiveAnswer(long long lo, long long hi, long long d) {

    bool can1 = (lo <= d);
    bool can0 = (d + 1 <= hi);

    if (!can1 && !can0) return -1;

    if (can1 && !can0) return 1;
    if (!can1 && can0) return 0;

    __int128 len1 = (__int128)d - (__int128)lo + 1;
    __int128 len0 = (__int128)hi - (__int128)d;
    if (len0 > len1) return 0;
    if (len1 > len0) return 1;

    return 0;
}

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

    int T = 0;
    try {
        T = inf.readInt();
    } catch (...) {
        query_limit = 0;
        log_metrics();
        finish(_pe, "failed to read T from hidden input");
    }
    if (T < 1 || T > 100) {
        query_limit = 64LL * max(1, T);
        log_metrics();
        finish(_pe, "invalid T in hidden input");
    }

    vector<long long> rest;
    while (!inf.seekEof()) {
        long long x = 0;
        try {
            x = inf.readLong();
        } catch (...) {
            query_limit = 64LL * T;
            log_metrics();
            finish(_pe, "failed to read hidden tokens");
        }
        rest.push_back(x);
    }

    vector<HiddenCase> cases;
    cases.reserve(T);

    if ((long long)rest.size() == 2LL * T) {
        for (int i = 0; i < T; i++) {
            long long N = rest[2LL * i];
            long long C = rest[2LL * i + 1];
            if (!(N > 1 && N <= (long long)1e18)) finish(_pe, "invalid N in hidden input");
            if (!(C >= 1 && C <= N)) finish(_pe, "invalid C in hidden input");
            HiddenCase hc;
            hc.N = N;
            hc.fixed = true;
            hc.C = C;
            hc.lo = hc.hi = C;
            cases.push_back(hc);
        }
    } else if ((long long)rest.size() == 3LL * T) {
        for (int i = 0; i < T; i++) {
            long long N = rest[3LL * i];
            long long L = rest[3LL * i + 1];
            long long R = rest[3LL * i + 2];
            if (!(N > 1 && N <= (long long)1e18)) finish(_pe, "invalid N in hidden input");
            if (!(L >= 1 && L <= R && R <= N)) finish(_pe, "invalid [L,R] in hidden input");
            HiddenCase hc;
            hc.N = N;
            hc.fixed = false;
            hc.lo = L;
            hc.hi = R;
            cases.push_back(hc);
        }
    } else {
        query_limit = 64LL * T;
        log_metrics();
        finish(_pe, "unrecognized hidden input format (expected 2*T or 3*T numbers after T)");
    }

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

    log_metrics();

    cout << T << endl;

    for (int tc = 0; tc < T; tc++) {
        HiddenCase& hc = cases[tc];

        cout << hc.N << endl;

        long long prevP = -1;
        bool havePrev = false;
        unordered_set<long long> used;
        used.reserve(256);

        while (true) {
            string tok;
            if (!(cin >> tok)) {
                finish(_pe, "unexpected EOF from contestant");
            }

            char cmd = 0;
            string attached;
            if (!tok.empty() && (tok[0] == '?' || tok[0] == '=' || tok[0] == '!')) {
                cmd = tok[0];
                attached = tok.substr(1);
            } else {
                finish(_pe, "invalid command token");
            }

            if (cmd == '?') {
                string pstr;
                if (!attached.empty()) {
                    pstr = attached;
                } else {
                    if (!(cin >> pstr)) finish(_pe, "missing P after '?'");
                }

                long long P = 0;
                if (!parseLongLongStrict(pstr, P)) finish(_pe, "P is not a valid integer");
                if (P < 1 || P > hc.N) finish(_pe, "P out of range");
                if (used.find(P) != used.end()) finish(_pe, "repeated P");
                used.insert(P);

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

                int ans = 0;

                if (!havePrev) {

                    ans = 0;
                    havePrev = true;
                    prevP = P;
                } else {
                    long long d = absDiffLL(prevP, P);

                    if (hc.fixed) {
                        ans = (d >= hc.C) ? 1 : 0;
                    } else {
                        int chosen = chooseAdaptiveAnswer(hc.lo, hc.hi, d);
                        if (chosen < 0) {
                            finish(_pe, "internal infeasible state");
                        }
                        ans = chosen;
                        if (ans == 1) {
                            hc.hi = min(hc.hi, d);
                        } else {
                            hc.lo = max(hc.lo, d + 1);
                        }
                        if (hc.lo > hc.hi) {
                            finish(_pe, "internal interval became empty");
                        }
                    }

                    prevP = P;
                }

                cout << ans << endl;
                continue;
            }

            if (cmd == '=' || cmd == '!') {
                string gstr;
                if (!attached.empty()) {
                    gstr = attached;
                } else {
                    if (!(cin >> gstr)) finish(_pe, "missing C after '='/'!'");
                }

                long long G = 0;
                if (!parseLongLongStrict(gstr, G)) finish(_pe, "guessed C is not a valid integer");
                if (G < 1 || G > hc.N) finish(_pe, "guessed C out of range");

                if (hc.fixed) {
                    if (G != hc.C) {
                        finish(_wa, "wrong answer");
                    }
                } else {
                    if (hc.lo != hc.hi || G != hc.lo) {
                        finish(_wa, "wrong answer");
                    }
                }
                break;
            }

            finish(_pe, "unknown command");
        }
    }

    finish(_ok, "accepted");
}

#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 T = opt<long long>("T", 1LL);

    auto pickN = [&](int seed) -> long long {

        if (seed == 1) return 2;
        if (seed == 2) return 3;
        if (seed == 3) return 64;

        long long lo = 1'000'000'000'000LL;
        long long hi = 1'000'000'000'000'000'000LL;

        int t = rnd.next(0, 9);
        if (t == 0) return 1'000'000'000'000'000'000LL;
        if (t == 1) return 999'999'999'999'999'937LL;   // near 1e18, prime-ish
        if (t == 2) return (1LL << 59) - 1;             // Mersenne-like (within 1e18)
        if (t == 3) return (1LL << 59);                 // power of two (within 1e18)
        if (t == 4) return 999'999'937'000'000'007LL;

        return rnd.next(lo, hi);
    };

    auto pickC_non = [&](long long N, int seed) -> long long {

        if (seed == 1) return 1;
        if (seed == 2) return 3;
        if (seed == 3) return 33;

        int t = rnd.next(0, 11);
        if (t == 0) return 1;
        if (t == 1) return N;
        if (t == 2) return max(1LL, N / 2);
        if (t == 3) return min(N, max(1LL, N / 2 + 1));
        if (t == 4) return min(N, 63LL);
        if (t == 5) return min(N, 64LL);
        if (t == 6) return min(N, 65LL);
        if (t == 7) {

            long long p = 1;
            while (p < N && p <= (LLONG_MAX / 2)) p <<= 1;
            long long cand = min(N, p);
            return max(1LL, cand);
        }
        if (t == 8) {

            long long p = 1;
            while ((p << 1) <= N && p <= (LLONG_MAX / 2)) p <<= 1;
            long long cand = min(N, p - 1);
            return max(1LL, cand);
        }
        if (t == 9) {

            long long s = (long long) sqrt((long double)N);
            s = max(1LL, min(N, s));
            return s;
        }
        if (t == 10) {

            long long s = (long long) sqrt((long double)N);
            long long cand = N - s;
            return max(1LL, min(N, cand));
        }

        return rnd.next(1LL, N);
    };

    auto pickParams_adp = [&](long long N, int seed, long long &L, long long &R) {

        if (seed == 1) { L = 1; R = 1; return; }
        if (seed == 2) { L = N; R = N; return; }
        if (seed == 3) { L = 32; R = 33; return; }
        int t = rnd.next(0, 9);
        if (t == 0) { L = 1; R = N; return; }
        if (t == 1) {
            long long mid = max(1LL, N / 2);
            long long width = min(N, 1000LL);
            L = max(1LL, mid - width);
            R = min(N, mid + width);
            return;
        }
        if (t == 2) {
            L = 1;
            R = min(N, 70LL);
            return;
        }
        if (t == 3) {
            L = min(N, 65LL);
            R = min(N, 5000LL);
            return;
        }
        if (t == 4) {
            long long width = min(N, 100000LL);
            L = max(1LL, N - width);
            R = N;
            return;
        }
        if (t == 5) {
            long long s = (long long) sqrt((long double)N);
            long long width = max(1LL, s / 10);
            L = max(1LL, s - width);
            R = min(N, s + width);
            return;
        }
        if (t == 6) {
            long long p = 1;
            while ((p << 1) <= N && p <= (LLONG_MAX / 2)) p <<= 1;
            long long width = min(N, 2048LL);
            L = max(1LL, p - width);
            R = min(N, p + width);
            return;
        }
        if (t == 7) {
            long long width = rnd.next(1LL, min(N, 1'000'000LL));
            long long center = rnd.next(1LL, N);
            L = max(1LL, center - width);
            R = min(N, center + width);
            if (L > R) swap(L, R);
            return;
        }

        L = 1;
        R = N;
    };

    int seed = 1;
    if (argc >= 2) {

        seed = atoi(argv[1]);
        if (seed <= 0) seed = 1;
    }

    (void)T;

    long long N = pickN(seed);

    if (mode == "non") {
        long long C = pickC_non(N, seed);

        cout << 1 << "\n";
        cout << N << " " << C << "\n";
        return 0;
    } else if (mode == "adp") {
        long long L, R;
        pickParams_adp(N, seed, L, R);

        cout << 1 << "\n";
        cout << N << " " << L << " " << R << "\n";
        return 0;
    } else {

        long long C = pickC_non(N, seed);
        cout << 1 << "\n";
        cout << N << " " << C << "\n";
        return 0;
    }
}


### Problem Statement

This is an **interactive task** (where your program interacts with the judge's program via Standard Input and Output).

You are given integers $N$, $L$, and $R$.
You play the following game against the judge:

> There are $N$ cards numbered $1$ through $N$ on the table.
> The players alternately perform the following operation:
>
> * choose an integer pair $(x, y)$ satisfying $1 \leq x \leq N$, $L \leq y \leq R$ such that all of the $y$ cards $x, x+1, \dots, x+y-1$ remain on the table, and remove cards $x, x+1, \dots, x+y-1$ from the table.
>
> The first player to become unable to perform the operation loses, and the other player wins.

Choose whether to go first or second, and play the game against the judge to win.

### Constraints

* $1 \leq N \leq 2000$
* $1 \leq L \leq R \leq N$
* $N$, $L$, and $R$ are integers.

### Input and Output

This is an interactive task (where your program interacts with the judge's program via Standard Input and Output).

Initially, receive $N$, $L$, and $R$, given from the input in the following format:

```
$N$ $L$ $R$
```

First, you choose whether to go first or second. Print `First` if you choose to go first, and `Second` if you choose to go second.

Then, the game immediately starts. If you choose to go first, the judge goes second, and vice versa. You are to interact with the judge via input and output until the game ends to win the game.

In your turn, print an integer pair $(x, y)$ that you choose in the operation in the following format. If there is no $(x, y)$ that you can choose, print $(x, y) = (0, 0)$ instead.

```
$x$ $y$
```

In the judge's turn, the judge print an integer pair $(a, b)$ in the following format:

```
$a$ $b$
```

Here, it is guaranteed that $(a, b)$ is of one of the following three kinds.

* If $(a, b) = (0, 0)$: the judge is unable to perform the operation. In other words, you have won the game.
* If $(a, b) = (-1, -1)$: you have chosen an illegal $(x, y)$ or printed $(0, 0)$. In other words, you have lost the game.
* Otherwise: the judge has performed the operation with $(x,y) = (a,b)$. It is guaranteed that judge chooses valid $(x, y)$.

If the judge returns $(a,b)=(0,0)$ or $(a,b)=(-1,-1)$, the game has already ended. In that case, terminate the program immediately.

### Notes

* **After each output, add a newline and then flush Standard Output. Otherwise, you may get a TLE verdict.**
* **If an invalid output is printed during the interaction, or if the program terminates halfway, the verdict will be indeterminate.** Especially, note that if a runtime error occurs during the execution of the program, you may get a WA or TLE verdict instead of a RE verdict.
* Terminate the program immediately after the game ends. Otherwise, the verdict will be indeterminate.

### Sample Interaction

The following is a sample interaction where $N = 6, L = 1$, and $R = 2$.

| Input | Output | Description |
| --- | --- | --- |
| `6 1 2` |  | Initially, you are given integers $N$, $L$, and $R$. |
|  | `First` | You choose to go first and start the game. |
|  | `2 1` | $(x, y) = (2, 1)$ is chosen to remove card $2$. |
| `3 2` |  | $(x, y) = (3, 2)$ is chosen to remove cards $3, 4$. |
|  | `6 1` | $(x, y) = (6, 1)$ is chosen to remove card $6$. |
| `5 1` |  | $(x, y) = (5, 1)$ is chosen to remove card $5$. |
|  | `1 1` | $(x, y) = (1, 1)$ is chosen to remove card $1$. |
| `0 0` |  | The judge is unable to perform the operation, so you win. |

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

using namespace std;

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

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 N, L, R;
vector<int> G;

vector<bitset<2048>> reachable_sets;
vector<bool> board;

struct Segment {
    int start;
    int len;
};

void precompute_grundy() {
    G.assign(N + 1, 0);
    reachable_sets.resize(N + 1);

    reachable_sets[0].set(0);

    for (int k = 1; k <= N; ++k) {
        bitset<2048> options;

        for (int y = L; y <= R; ++y) {
            int S = k - y;
            if (S < 0) break;
            options |= reachable_sets[S];
        }

        int g = 0;
        while (options.test(g)) g++;
        G[k] = g;

        for (int x = 0; x <= k; ++x) {
            if (k + x > N) break;
            reachable_sets[k + x].set(G[k] ^ G[x]);
        }
    }
}

vector<Segment> get_segments() {
    vector<Segment> segs;
    int current_start = -1;
    int current_len = 0;
    for (int i = 1; i <= N; ++i) {
        if (board[i]) {
            if (current_start == -1) current_start = i;
            current_len++;
        } else {
            if (current_start != -1) {
                segs.push_back({current_start, current_len});
                current_start = -1;
                current_len = 0;
            }
        }
    }
    if (current_start != -1) {
        segs.push_back({current_start, current_len});
    }
    return segs;
}

void play_judge_move() {
    vector<Segment> segs = get_segments();
    int xor_sum = 0;
    for (auto& s : segs) xor_sum ^= G[s.len];

    int best_start = 0;
    int move_y = 0;
    int move_i = 0;
    bool found = false;

    if (xor_sum != 0) {
        for (auto& s : segs) {
            int target = G[s.len] ^ xor_sum;

            for (int y = L; y <= R; ++y) {
                int rem = s.len - y;
                if (rem < 0) break;

                if (reachable_sets[rem].test(target)) {

                    for (int i = 0; i <= rem; ++i) {
                        int j = rem - i;
                        if ((G[i] ^ G[j]) == target) {
                            best_start = s.start;
                            move_y = y;
                            move_i = i;
                            found = true;
                            goto done;
                        }
                    }
                }
            }
        }
    }

    if (!found) {
        for (auto& s : segs) {
            if (s.len >= L) {
                best_start = s.start;
                move_y = L;
                move_i = 0;
                found = true;
                goto done;
            }
        }
    }

done:
    if (!found) {

        cout << "0 0" << endl;
        finish(_ok, "Judge unable to move, Contestant wins");
    } else {

        int x = best_start + move_i;
        int y = move_y;

        for (int k = 0; k < y; ++k) board[x + k] = false;

        cout << x << " " << y << endl;
        queries++;
        log_metrics();
    }
}

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

    N = inf.readInt(1, 2000, "N");
    L = inf.readInt(1, N, "L");
    R = inf.readInt(L, N, "R");

    query_limit = N + 100;
    log_metrics();

    precompute_grundy();
    board.assign(N + 1, true);

    cout << N << " " << L << " " << R << endl;

    string side = "";
    if (!(cin >> side)) {
        finish(_wa, "Cannot read side choice");
    }

    bool contestant_turn = false;
    if (side == "First") {
        contestant_turn = true;
    } else if (side == "Second") {
        contestant_turn = false;
    } else {
        finish(_wa, "Invalid side choice (expected First/Second): " + side);
    }

    int max_turns = 5000;
    while (max_turns--) {
        if (contestant_turn) {

            string t1;
            if (!(cin >> t1)) {
                 finish(_wa, "Unexpected EOF reading move");
            }

            int x = -1, y = -1;

            if (t1 == "?") {
                if (!(cin >> x >> y)) finish(_wa, "Bad format after ?");
            } else if (t1 == "!") {
                finish(_wa, "Unexpected '!' output");
            } else {
                try {
                    x = stoi(t1);
                } catch (...) {
                    finish(_wa, "Token not integer: " + t1);
                }
                if (!(cin >> y)) finish(_wa, "Cannot read y");
            }

            if (x == 0 && y == 0) {
                cout << "-1 -1" << endl;
                finish(_wa, "Contestant output 0 0 (resignation)");
            }

            if (x < 1 || x > N || y < L || y > R) {
                cout << "-1 -1" << endl;
                finish(_wa, format("Invalid range: x=%d y=%d (N=%d, L=%d, R=%d)", x, y, N, L, R));
            }

            bool possible = true;
            for (int k = 0; k < y; ++k) {
                if (x + k > N || !board[x + k]) {
                    possible = false;
                    break;
                }
            }
            if (!possible) {
                cout << "-1 -1" << endl;
                finish(_wa, format("Invalid move: cards overlap or removed at x=%d y=%d", x, y));
            }

            for (int k = 0; k < y; ++k) board[x + k] = false;
            queries++;
            log_metrics();

            contestant_turn = false;

        } else {
            play_judge_move();
            contestant_turn = true;
        }
    }

    finish(_pe, "Game limit exceeded");
    return 0;
}

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

using namespace std;

const int MAXN = 2005;
const int MAX_VAL = 2048;

int N, L, R;
int G[MAXN];

int can_make_split[MAXN][MAX_VAL];

int freq[MAX_VAL];

set<pair<int,int>> intervals;

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

void log_metrics() {
    if (query_limit > 0) {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    }
}

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

void precompute() {

    for(int i=0; i<MAXN; ++i) {
        for(int j=0; j<MAX_VAL; ++j) {
            can_make_split[i][j] = -1;
        }
    }

    G[0] = 0;
    can_make_split[0][0] = 0;

    memset(freq, 0, sizeof(freq));

    int current_window_start = 1 - R;
    int current_window_end = 1 - L;

    for (int k = 1; k <= N; ++k) {

        int target_start = k - R;
        int target_end = k - L;

        while (current_window_end < target_end) {
            current_window_end++;
            int rem = current_window_end;
            if (rem >= 0) {
                for (int v = 0; v < MAX_VAL; ++v) {
                    if (can_make_split[rem][v] != -1) freq[v]++;
                }
            }
        }

        while (current_window_start < target_start) {
            int rem = current_window_start;
            if (rem >= 0) {
                for (int v = 0; v < MAX_VAL; ++v) {
                    if (can_make_split[rem][v] != -1) freq[v]--;
                }
            }
            current_window_start++;
        }

        int mex = 0;
        while (freq[mex] > 0) mex++;
        G[k] = mex;

        for (int s = 0; s <= k; ++s) {
            int val = G[s] ^ G[k - s];
            if (val < MAX_VAL) {

                if (can_make_split[k][val] == -1) {
                    can_make_split[k][val] = s;
                }
            }
        }
    }
}

bool remove_interval(int x, int y) {
    int l = x;
    int r = x + y - 1;

    auto it = intervals.upper_bound({l, 2000000000});
    if (it == intervals.begin()) return false;
    it--;

    pair<int, int> cur = *it;

    if (cur.first <= l && cur.second >= r) {
        intervals.erase(it);

        if (l > cur.first) {
            intervals.insert({cur.first, l - 1});
        }

        if (r < cur.second) {
            intervals.insert({r + 1, cur.second});
        }
        return true;
    }
    return false;
}

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

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

    N = inf.readInt();
    L = inf.readInt();
    R = inf.readInt();

    query_limit = N;
    log_metrics();

    precompute();

    cout << N << " " << L << " " << R << endl;

    intervals.insert({1, N});

    string side;
    if (!(cin >> side)) {
        finish_interaction(_pe, "No side choice provided");
    }

    bool my_turn = false;
    if (side == "First") {
        my_turn = false;
    } else if (side == "Second") {
        my_turn = true;
    } else {
        finish_interaction(_pe, "Invalid side choice: " + side);
    }

    while (true) {

        if (queries > 2 * N + 200) {
            finish_interaction(_pe, "Too many moves/Loop detected");
        }

        if (my_turn) {

            int nim_sum = 0;
            for (auto p : intervals) {
                nim_sum ^= G[p.second - p.first + 1];
            }

            int chosen_x = -1, chosen_y = -1;
            bool found = false;

            if (nim_sum != 0) {

                for (auto p : intervals) {
                    int len = p.second - p.first + 1;
                    int target = G[len] ^ nim_sum;

                    if (target < G[len]) {

                        int min_rem = max(0, len - R);
                        int max_rem = len - L;

                        for (int rem = min_rem; rem <= max_rem; ++rem) {
                            if (can_make_split[rem][target] != -1) {
                                int s = can_make_split[rem][target];

                                chosen_y = len - rem;
                                chosen_x = p.first + s;
                                found = true;
                                break;
                            }
                        }
                    }
                    if (found) break;
                }
            }

            if (!found) {

                for (auto p : intervals) {
                    if (p.second - p.first + 1 >= L) {
                        chosen_x = p.first;
                        chosen_y = L;
                        found = true;
                        break;
                    }
                }
            }

            if (!found) {

                cout << "0 0" << endl;
                finish_interaction(_ok, "Judge has no moves (Contestant wins)");
            } else {

                remove_interval(chosen_x, chosen_y);
                cout << chosen_x << " " << chosen_y << endl;
                my_turn = false;
            }

        } else {

            int x, y;
            if (!(cin >> x >> y)) {
                finish_interaction(_wa, "Unexpected EOF while reading contestant move");
            }
            queries++;

            if (x == 0 && y == 0) {
                cout << "-1 -1" << endl;
                finish_interaction(_wa, "Contestant resigned (0 0)");
            }

            if (x < 1 || x > N || y < L || y > R) {
                cout << "-1 -1" << endl;
                finish_interaction(_wa, "Move parameters out of bounds");
            }

            if (!remove_interval(x, y)) {
                cout << "-1 -1" << endl;
                finish_interaction(_wa, "Invalid move: cards not present on table");
            }

            my_turn = true;
        }
    }

    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 seedVal = -1;
    try {
        string s(argv[1]);
        if (!s.empty() && all_of(s.begin(), s.end(), ::isdigit)) {
            seedVal = stoll(s);
        }
    } catch (...) {
        seedVal = -1;
    }

    int n, l, r;

    if (seedVal >= 1 && seedVal <= 5) {
        if (seedVal == 1) {

            n = 1; l = 1; r = 1;
        } else if (seedVal == 2) {

            n = 2000; l = 1; r = 1;
        } else if (seedVal == 3) {

            n = 2000; l = 1; r = 2000;
        } else if (seedVal == 4) {

            n = 2000; l = 1000; r = 1000;
        } else {

            n = 6; l = 1; r = 2;
        }
    } else {

        if (rnd.next(4) == 0) {
            n = rnd.next(1, 50);
        } else {
            n = rnd.next(1800, 2000);
        }

        int type = rnd.next(100);
        if (type < 20) {

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

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

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

            l = rnd.next(1, n);
            r = min(n, l + rnd.next(0, 50));
        } else {

            l = rnd.next(1, n);
            r = rnd.next(l, n);
        }
    }

    cout << n << " " << l << " " << r << endl;

    return 0;
}


This is an interactive problem.

You are given $n$ boxes, indexed from $1$ to $n$. The boxes look identical, but each one has a hidden power value $a_i$, which is either $1$ or $2$.

You want to determine the power value of each box. To do so, you conduct the following experiment. Initially, the $i$-th box is placed at coordinate $i$ on a number line ($1 \le i \le n$).

You are allowed to perform the following two types of queries:

* "swap $x$" ($1 \le x \le n - 1$): Swap the boxes currently located at coordinates $x$ and $x + 1$. Note that this change is permanent and affects all subsequent queries.
* "throw $x$" ($1 \le x \le n$): Throw a ball at the box located at coordinate $x$. The ball travels $p$ units forward to coordinate $x + p$ if the power value of the box is $p$. If there is a box at the new coordinate, the ball jumps again using the power of that box. This continues until the ball lands on a coordinate without a box. As a response, you are given the total number of jumps the ball made before stopping.

Your task is to determine the power value of each box using no more than $\left\lceil \frac{3n}{2} \right\rceil$ queries in total, counting both swap and throw queries.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

The first and the only line of each test case contains a single integer $n$ ($2 \le n \le 1000$) — the number of boxes.

It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$.

Interaction

The interaction for each test case begins by reading the integer $n$.

To make a query, output a line in one of the following formats:

* "swap $x$" (without quotes) ($1 \le x \le n - 1$): Swap the boxes currently located at coordinates $x$ and $x + 1$.
* "throw $x$" (without quotes) ($1 \le x \le n$): Throw a ball at the box located at coordinate $x$. The jury will respond with an integer representing the number of jumps the ball made before stopping.

Note that queries are case sensitive.

Once you have determined the power value of each box, output a line in the following format:

* "! $a_1 \space a_2 \space \ldots \space a_n$" (without quotes): Here, $a_i$ is the power value of the box initially located at coordinate $i$ ($1 \le i \le n$). After submitting the final answer, proceed on to the next test case.

Note that submitting the final answer with the previous query does not count towards the limit of $\left\lceil \frac{3n}{2} \right\rceil$ queries.

If your program exceeds $\left\lceil \frac{3n}{2} \right\rceil$ queries in one test case, your program must terminate immediately to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.

After outputting a query, do not forget to output the end of the 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;
* sys.stdout.flush() in Python;
* std::io::stdout().flush() in Rust;
* see the documentation for other languages.

The interactor is non-adaptive; the power values of the boxes remain constant throughout the interaction.

Example

Input

```
2
4

2

3

3

2

2

1
```

Output

```
throw 2

swap 3
throw 2

throw 1

! 2 1 2 1

throw 1

swap 1
throw 1

! 1 2
```

Note

Below is the interaction process in the example:

|  |  |  |
| --- | --- | --- |
| Solution | Jury | Explanation |
|  | 2 | There are $2$ test cases. |
|  | 4 | There are $4$ boxes in the first test case. The hidden power values are $a = [2,1,2,1]$. |
| throw 2 | 2 | Throw a ball at the box located at coordinate $2$. The ball travels through coordinates $2 \to 3 \to 5$ and stops at coordinate $5$, so the response is $2$. |
| swap 3 |  | Swap the boxes located at coordinate $3$ and $4$. Now box $3$ is located at coordinate $4$ and box $4$ is located at coordinate $3$. |
| throw 2 | 3 | Throw a ball at the box located at coordinate $2$. The ball travels through coordinates $2 \to 3 \to 4 \to 6$ and stops at coordinate $6$, so the response is $3$. Note that the response is different because of the swap. |
| throw 1 | 3 | Throw a ball at the box located at coordinate $1$. The ball travels through coordinates $1 \to 3 \to 4 \to 6$ and stops at coordinate $6$, so the response is $3$. |
| ! 2 1 2 1 |  | The solution concludes that the power values are $[2,1,2,1]$. |
|  | 2 | There are $2$ boxes in the second test case. The hidden power values are $a = [1, 2]$. |
| throw 1 | 2 | Throw a ball at the box located at coordinate $1$. The ball travels through coordinates $1 \to 2 \to 4$ and stops at coordinate $4$, so the response is $2$. |
| swap 1 |  | Swap the boxes located at coordinate $1$ and $2$. Now box $1$ is located at coordinate $2$ and box $2$ is located at coordinate $1$. |
| throw 1 | 1 | Throw a ball at the box located at coordinate $1$. The ball travels through coordinates $1 \to 3$ and stops at coordinate $3$, so the response is $1$. |
| ! 1 2 |  | The solution concludes that the power values are $[1,2]$. |

Empty lines in the example input and output are given only for better readability; you don't need to output them in your solution.

Note that in the first test case, the given queries are in fact insufficient to uniquely determine the power values; they are given only to illustrate the input/output format.

#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 readToken(string& s) {
    if (!(cin >> s)) return false;
    return true;
}

static bool parseLLStrict(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[0] == '-') {
        neg = true;
        i = 1;
    } else if (s[0] == '+') {
        i = 1;
    }
    if (i == (int)s.size()) return false;
    for (int j = i; j < (int)s.size(); j++) {
        if (s[j] < '0' || s[j] > '9') return false;
    }
    __int128 val = 0;
    for (int j = i; j < (int)s.size(); j++) {
        val = val * 10 + (s[j] - '0');
        if (val > (__int128)LLONG_MAX + 1) return false;
    }
    if (neg) val = -val;
    if (val < (__int128)LLONG_MIN || val > (__int128)LLONG_MAX) return false;
    out = (long long)val;
    return true;
}

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

    try {
        int t = inf.readInt(1, 500, "t");
        struct CaseData {
            int n;
            vector<int> a;
        };
        vector<CaseData> cases;
        cases.reserve(t);

        long long totalBudget = 0;
        for (int tc = 0; tc < t; tc++) {
            int n = inf.readInt(2, 1000, "n");
            vector<int> a(n + 1, 1);
            for (int i = 1; i <= n; i++) a[i] = inf.readInt(1, 2, ("a" + to_string(i)).c_str());
            cases.push_back(CaseData{n, std::move(a)});
            totalBudget += (3LL * n + 1) / 2;
        }

        query_limit = totalBudget;
        log_metrics();

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

        cout << t << endl;
        for (int tc = 0; tc < t; tc++) {
            int n = cases[tc].n;
            const vector<int>& a = cases[tc].a;

            vector<int> pos_to_box(n + 1), box_to_pos(n + 1);
            for (int i = 1; i <= n; i++) {
                pos_to_box[i] = i;
                box_to_pos[i] = i;
            }

            cout << n << endl;

            while (true) {
                string cmd;
                if (!readToken(cmd)) finish(_pe, "unexpected EOF while waiting for a command");

                if (cmd == "swap") {
                    string xs;
                    if (!readToken(xs)) finish(_pe, "unexpected EOF after swap");
                    long long xll;
                    if (!parseLLStrict(xs, xll)) finish(_pe, "swap argument is not an integer");
                    if (xll < 1 || xll > n - 1) finish(_pe, "swap index out of range");
                    int x = (int)xll;

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

                    int b1 = pos_to_box[x];
                    int b2 = pos_to_box[x + 1];
                    pos_to_box[x] = b2;
                    pos_to_box[x + 1] = b1;
                    box_to_pos[b1] = x + 1;
                    box_to_pos[b2] = x;
                } else if (cmd == "throw") {
                    string xs;
                    if (!readToken(xs)) finish(_pe, "unexpected EOF after throw");
                    long long xll;
                    if (!parseLLStrict(xs, xll)) finish(_pe, "throw argument is not an integer");
                    if (xll < 1 || xll > n) finish(_pe, "throw index out of range");
                    int x = (int)xll;

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

                    int jumps = 0;
                    int cur = x;
                    while (cur <= n) {
                        jumps++;
                        int box = pos_to_box[cur];
                        int p = a[box];
                        cur += p;
                    }

                    cout << jumps << endl;
                } else if (cmd == "!") {
                    vector<int> ans(n + 1, -1);
                    for (int i = 1; i <= n; i++) {
                        string ts;
                        if (!readToken(ts)) finish(_pe, "unexpected EOF in final answer");
                        long long vll;
                        if (!parseLLStrict(ts, vll)) finish(_pe, "final answer contains non-integer token");
                        if (vll != 1 && vll != 2) finish(_pe, "final answer values must be 1 or 2");
                        ans[i] = (int)vll;
                    }
                    for (int i = 1; i <= n; i++) {
                        if (ans[i] != a[i]) finish(_wa, "wrong final answer");
                    }
                    break;
                } else {
                    finish(_pe, "unknown command");
                }
            }
        }

        string extra;
        if (readToken(extra)) finish(_pe, "extra output after finishing all test cases");
        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 vector<int> make_case_non(int n, long long seedVal, int p2permille) {
    n = max(n, 2);
    vector<int> a(n + 1, 1);

    if (seedVal == 1) {
        n = 2;
        a.assign(n + 1, 1);
        a[1] = 1;
        a[2] = 2;
        return a;
    }
    if (seedVal == 2) {
        n = 1000;
        a.assign(n + 1, 2);
        return a;
    }
    if (seedVal == 3) {
        n = 1000;
        a.assign(n + 1, 1);
        for (int i = 1; i <= n; i++) a[i] = (i % 2 ? 1 : 2);
        return a;
    }

    if (n < 900) n = 1000;
    a.assign(n + 1, 1);

    int i = 1;
    while (i <= n) {
        int segType = rnd.next(0, 4);
        int len = rnd.next(10, 80);
        len = min(len, n - i + 1);

        if (segType == 0) {
            for (int j = 0; j < len; j++) a[i + j] = 1;
        } else if (segType == 1) {
            for (int j = 0; j < len; j++) a[i + j] = 2;
        } else if (segType == 2) {
            for (int j = 0; j < len; j++) a[i + j] = (j % 2 == 0 ? 1 : 2);
        } else if (segType == 3) {
            for (int j = 0; j < len; j++) a[i + j] = (j % 2 == 0 ? 2 : 1);
        } else {
            for (int j = 0; j < len; j++) {
                int m = j % 3;
                a[i + j] = (m == 0 ? 2 : 1);
            }
        }
        i += len;
    }

    int suf = min(120, n);
    int start = n - suf + 1;
    for (int k = 0; k < suf; k++) {
        int pos = start + k;
        if (k < suf / 2) a[pos] = (k % 2 == 0 ? 1 : 2);
        else a[pos] = (rnd.next(0, 9) < 7 ? 1 : 2);
    }

    int target2 = (int)((1LL * n * p2permille + 500) / 1000);
    target2 = max(0, min(n, target2));

    int cnt2 = 0;
    for (int idx = 1; idx <= n; idx++) cnt2 += (a[idx] == 2);

    vector<int> pos1, pos2;
    pos1.reserve(n);
    pos2.reserve(n);
    for (int idx = 1; idx <= n; idx++) {
        if (a[idx] == 1) pos1.push_back(idx);
        else pos2.push_back(idx);
    }

    while (cnt2 < target2 && !pos1.empty()) {
        int pick = rnd.next(0, (int)pos1.size() - 1);
        int idx = pos1[pick];
        a[idx] = 2;
        cnt2++;
        pos1[pick] = pos1.back();
        pos1.pop_back();
    }
    while (cnt2 > target2 && !pos2.empty()) {
        int pick = rnd.next(0, (int)pos2.size() - 1);
        int idx = pos2[pick];
        a[idx] = 1;
        cnt2--;
        pos2[pick] = pos2.back();
        pos2.pop_back();
    }

    for (int idx = 1; idx <= n; idx++) if (a[idx] != 1 && a[idx] != 2) a[idx] = 1;
    return a;
}

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

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", 1000);
    int p2permille = opt<int>("p2", 500);
    p2permille = max(0, min(1000, p2permille));

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

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

        mode = "non";
    }

    cout << 1 << "\n";

    if (mode == "non") {
        vector<int> a = make_case_non(nOpt, seedVal, p2permille);
        int n = (int)a.size() - 1;
        cout << n << "\n";
        for (int i = 1; i <= n; i++) {
            if (i > 1) cout << ' ';
            cout << a[i];
        }
        cout << "\n";
    } else {
        int n = max(nOpt, 2);
        if (seedVal == 1) n = 2;
        else if (seedVal == 2 || seedVal == 3) n = 1000;
        else if (n < 900) n = 1000;

        int k2;
        if (seedVal == 1) k2 = 1;
        else if (seedVal == 2) k2 = n;
        else if (seedVal == 3) k2 = n / 2;
        else {
            k2 = (int)((1LL * n * p2permille + 500) / 1000);
        }
        k2 = max(0, min(n, k2));

        cout << n << " " << k2 << "\n";
    }

    return 0;
}


This is an interactive problem.

Madeline is playing with a pointless machine. The pointless machine has a hidden tree of size $n$, and Madeline has to find the edges of the tree by asking the machine.

In a query, Madeline will give the machine a permutation $p$ of $[1,2,\ldots,n]$, and the machine will return a sequence $q_1, q_2, \ldots, q_n$, where $q_i$ is the number of edges of the induced subgraph formed by the vertices $\{p_1,p_2,\ldots,p_i\}$.

Here, an induced subgraph of a graph $G(V,E)$ formed by a subset of vertices $V' \subseteq V$, is a graph consisting of vertices from this subset and all edges between vertices from subset that are present in original graph $G$.

However, the machine works slowly, so Madeline can only get the results at once after all queries are completed. The memory of this machine is not very large either, so Madeline can only ask $31$ times. She doesn't know how to solve it, so she invited you to help her.

Note that the interactor is non-adaptive. That is, tree is fixed in advance and doesn't change with your queries.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

The only line of each test case contains a single integer $n$ ($3\le n\le 5\cdot 10^4$) — the size of the tree.

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

Interaction

The interaction begins by reading the integer $n$.

Then, output a single integer $k$ ($1 \leq k \leq 31$) — the number of queries.

To ask a query, output a line in the following format:

* $p_{i,1}\,p_{i,2}\,\ldots\,p_{i,n}$ ($1 \leq p_{i,j} \leq n$, the $p_{i,j}$ are distinct for each $i$) — a query described above.

Once you've asked all $k$ queries, read $k$ lines of $n$ integers $q_{i,j}$ — the responses to the queries as described above.

When you know the hidden tree, output $n-1$ lines in the following format:

* $u,v$ ($1\leq u,v\leq n$) — an edge $(u,v)$ in the hidden tree.

Then, move on to the next test case, or terminate the program if there are no more test cases.

After printing all $k$ queries do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

Example

Input

```
3
3

0 1 2
0 0 2

4

0 1 1 3
0 1 1 3
0 1 2 3

5

0 0 1 3 4
```

Output

```
2
1 2 3
1 3 2

1 2
2 3

3
3 2 4 1
1 4 3 2
1 2 3 4

2 3
1 2
4 1

1
1 2 3 4 5

1 4
4 3
3 2
5 3
```

Note

Visualizer link

For the first test case:

* The first query has answer 0 1 2, since only edge $(1, 2)$ is in the induced subgraph formed by $\{1,2\}$.
* The second query has answer 0 0 2, since no edges are in the induced subgraph formed by $\{1,3\}$.

For the third test case:

* Edges $(2,3)$, $(3,4)$, and $(4,1)$ are in the induced subgraph formed by $\{1,2,3,4\}$, so $q_{1,4}=3$.

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

using namespace std;

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

void log_metrics() {
    if (query_limit == 0) return;
    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());
}

void fail_query(const string& msg) {
    cout << "-1" << endl;
    finish(_wa, msg);
}

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

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

    int t = inf.readInt();

    query_limit = 31LL * t;

    cout << t << endl;

    for (int cas = 0; cas < t; ++cas) {

        int n = inf.readInt();
        vector<vector<int>> adj(n + 1);
        set<pair<int, int>> hidden_set;

        for (int i = 0; i < n - 1; ++i) {
            int u = inf.readInt();
            int v = inf.readInt();
            if (u > v) swap(u, v);
            adj[u].push_back(v);
            adj[v].push_back(u);
            hidden_set.insert({u, v});
        }

        cout << n << endl;

        int k;
        if (!(cin >> k)) {
            finish(_wa, "Unexpected EOF reading k");
        }

        queries += k;
        log_metrics();

        if (k < 1 || k > 31) {
            fail_query(format("k must be in [1, 31], read %d", k));
        }

        vector<vector<int>> perms(k, vector<int>(n));
        for (int i = 0; i < k; ++i) {
            vector<bool> used(n + 1, false);
            for (int j = 0; j < n; ++j) {
                if (!(cin >> perms[i][j])) {
                    fail_query("Unexpected EOF reading permutation");
                }
                int val = perms[i][j];
                if (val < 1 || val > n) {
                    fail_query(format("Permutation value out of range: %d", val));
                }
                if (used[val]) {
                    fail_query(format("Duplicate value in permutation: %d", val));
                }
                used[val] = true;
            }
        }

        for (int i = 0; i < k; ++i) {

            vector<int> q(n);
            vector<bool> active(n + 1, false);
            int current_edges = 0;

            for (int j = 0; j < n; ++j) {
                int u = perms[i][j];
                active[u] = true;
                for (int v : adj[u]) {
                    if (active[v]) current_edges++;
                }
                q[j] = current_edges;
            }

            for (int j = 0; j < n; ++j) {
                cout << q[j] << (j == n - 1 ? "" : " ");
            }
            cout << "\n";
        }
        cout.flush();

        set<pair<int, int>> user_edges;
        for (int i = 0; i < n - 1; ++i) {
            int u, v;
            if (!(cin >> u >> v)) {
                finish(_wa, "Unexpected EOF reading answer edges");
            }
            if (u < 1 || u > n || v < 1 || v > n) {
                finish(_wa, format("Edge vertex out of range: %d %d", u, v));
            }
            if (u == v) finish(_wa, "Self loop in answer");
            if (u > v) swap(u, v);

            if (user_edges.count({u, v})) {
                finish(_wa, format("Duplicate edge in answer: %d %d", u, v));
            }
            user_edges.insert({u, v});
        }

        if (user_edges.size() != hidden_set.size()) {
            finish(_wa, "Wrong number of unique edges");
        }
        for (auto& e : user_edges) {
            if (!hidden_set.count(e)) {
                finish(_wa, format("Edge (%d, %d) is not in the hidden tree", e.first, e.second));
            }
        }
    }

    finish(_ok, "All test cases passed");
    return 0;
}

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

using namespace std;

vector<pair<int, int>> gen_uniform(int n) {
    if (n < 2) return {};
    if (n == 2) return {{1, 2}};
    vector<int> prufer(n - 2);
    vector<int> degree(n + 1, 1);
    for (int i = 0; i < n - 2; ++i) {
        prufer[i] = rnd.next(1, n);
        degree[prufer[i]]++;
    }

    set<int> leaves;
    for (int i = 1; i <= n; ++i) {
        if (degree[i] == 1) leaves.insert(i);
    }

    vector<pair<int, int>> edges;
    for (int v : prufer) {
        int leaf = *leaves.begin();
        leaves.erase(leaves.begin());
        edges.push_back({leaf, v});
        if (--degree[v] == 1) leaves.insert(v);
    }
    edges.push_back({*leaves.begin(), *leaves.rbegin()});
    return edges;
}

vector<pair<int, int>> gen_random_attach(int n) {
    vector<pair<int, int>> edges;
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    shuffle(p.begin(), p.end());

    for (int i = 1; i < n; ++i) {
        int u = p[i];
        int v = p[rnd.next(0, i - 1)];
        edges.push_back({u, v});
    }
    return edges;
}

vector<pair<int, int>> gen_path(int n) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    shuffle(p.begin(), p.end());
    vector<pair<int, int>> edges;
    for (int i = 0; i < n - 1; ++i) {
        edges.push_back({p[i], p[i+1]});
    }
    return edges;
}

vector<pair<int, int>> gen_star(int n) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    shuffle(p.begin(), p.end());
    vector<pair<int, int>> edges;
    for (int i = 1; i < n; ++i) {
        edges.push_back({p[0], p[i]});
    }
    return edges;
}

vector<pair<int, int>> gen_caterpillar(int n, int len) {
    if (len > n) len = n;
    if (len < 1) len = 1;

    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    shuffle(p.begin(), p.end());

    vector<pair<int, int>> edges;

    for (int i = 0; i < len - 1; ++i) {
        edges.push_back({p[i], p[i+1]});
    }

    for (int i = len; i < n; ++i) {
        int parent = p[rnd.next(0, len - 1)];
        edges.push_back({parent, p[i]});
    }
    return edges;
}

vector<pair<int, int>> gen_kary(int n, int k) {
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    shuffle(p.begin(), p.end());

    vector<pair<int, int>> edges;
    for (int i = 1; i < n; ++i) {
        int parent = (i - 1) / k;
        edges.push_back({p[parent], p[i]});
    }
    return edges;
}

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

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

    long long seed_val = atoll(argv[1]);
    if (n == -1) {
        if (seed_val == 1) n = 3;
        else if (seed_val == 2) n = 10;
        else if (seed_val <= 5) n = 100;
        else {

             if (rnd.next(0, 1)) n = 50000;
             else n = rnd.next(40000, 50000);
        }
    }

    cout << 1 << "\n";

    cout << n << "\n";

    if (mode == "adp") {

        return 0;
    }

    int type = 0;

    if (seed_val == 1) type = 2;
    else if (seed_val == 2) type = 0;
    else if (seed_val == 3) type = 3;
    else if (seed_val == 4) type = 2;
    else if (seed_val == 5) type = 6;
    else {

        type = rnd.next(0, 8);
    }

    vector<pair<int, int>> edges;
    switch(type) {
        case 0: edges = gen_uniform(n); break;
        case 1: edges = gen_random_attach(n); break;
        case 2: edges = gen_path(n); break;
        case 3: edges = gen_star(n); break;
        case 4: edges = gen_caterpillar(n, (int)(n * 0.8)); break;
        case 5: edges = gen_caterpillar(n, (int)(sqrt(n) + 1)); break;
        case 6: edges = gen_kary(n, 2); break;
        case 7: edges = gen_kary(n, 3); break;
        case 8: edges = gen_caterpillar(n, 10); break;
        default: edges = gen_uniform(n); break;
    }

    shuffle(edges.begin(), edges.end());

    for (auto& e : edges) {
        cout << e.first << " " << e.second << "\n";
    }

    return 0;
}


This is an interactive problem.

Bobo had an array $a$ , initially equal to $( 1 , 2 , \ldots , n )$ . He did the following operations with the array.

• For each $i$ from 1 to $n$ in this order, Bobo picked some index $j$ such that $i \leq j \leq \operatorname* { m i n } ( n , i + 2 )$ , and swapped $a _ { i }$ and $a _ { j }$ . Of course, if $i = j$ , then nothing happened after the operation.

Your goal is to determine the final array. You may ask questions of the following type.

• ? i j meaning the question “How do $a _ { i }$ and $a _ { j }$ compare to each other?”. Bobo will respond to this with one symbol $<$ or $>$ , meaning that $a _ { i }  a _ { j }$ , respectively.

You may ask no more than $\lfloor 5 n / 3 \rfloor + 5$ questions. After this, you must guess the array.

# Interaction Protocol

First, the interactor prints the number $n$ in a separate line ( $1 \leq n \leq 3 0 0 0 0$ ). Then the solution makes queries, where each query consists of printing $? \ \dot { \textbf { 1 } } \dot { \textbf { ] } }$ on a separate line, where $1 \leq i , j \leq n$ , and $i \neq j$ . After each query the interactor prints one character $<$ or $>$ on a separate line.

After the solution has finished asking questions, it must make a guess. If you think that the array is $( a _ { 1 } , \ldots , a _ { n } )$ , print ! a1 a2 ... $a _ { n }$ on a separate line and terminate.

If your solution makes more than $\lfloor 5 n / 3 \rfloor + 5$ queries, the interactor will finish with the WA verdict. If you do not flush the output after printing a query, you may receive the IL verdict.

Note that the interactor in this task is adaptive, i.e. the array may be generated at the runtime consistently with your questions.

# Example

standard input	standard output

5	？54

<	？51

>	？53

>	？31

<	？21

>	？52

>

	!23154

#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 << 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();
    vector<int> hidden_a(n);
    for (int i = 0; i < n; i++) {
        hidden_a[i] = inf.readInt();
    }

    query_limit = (5LL * n) / 3 + 5;

    log_metrics();

    cout << n << endl;

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

    while (true) {

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

        string token;

        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF: solution terminated without making a guess");
        }

        if (token == "!") {

            vector<int> user_a(n);
            for (int i = 0; i < n; i++) {
                if (!(cin >> user_a[i])) {
                    finish(_pe, "Unexpected EOF while reading answer array");
                }
            }

            bool correct = true;
            for (int i = 0; i < n; i++) {
                if (user_a[i] != hidden_a[i]) {
                    correct = false;
                    break;
                }
            }

            if (correct) {
                finish(_ok, "Correct guess");
            } else {
                finish(_wa, "Wrong guess");
            }
        } else {

            int i, j;

            if (token == "?") {
                if (!(cin >> i >> j)) {
                    finish(_pe, "Invalid query format (expected: ? i j)");
                }
            } else {

                try {
                    size_t pos;
                    i = stoi(token, &pos);
                    if (pos != token.size()) {

                        finish(_pe, "Invalid token '" + token + "' (expected '?' or integer)");
                    }
                } catch (...) {
                    finish(_pe, "Invalid token '" + token + "' (expected '?' or integer)");
                }

                if (!(cin >> j)) {
                    finish(_pe, "Invalid query format (expected: i j)");
                }
            }

            queries++;

            if (i < 1 || i > n || j < 1 || j > n) {
                finish(_pe, format("Query indices out of bounds: %d %d (n=%d)", i, j, n));
            }
            if (i == j) {
                finish(_pe, format("Query indices must be distinct: %d %d", i, j));
            }

            if (hidden_a[i - 1] < hidden_a[j - 1]) {
                cout << "<" << endl;
            } else {
                cout << ">" << endl;
            }

            if (queries % 1000 == 0) {
                log_metrics();
            }
        }
    }

    return 0;
}

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

using namespace std;

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

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());
}

void validate_indices(int i, int j, int n) {
    if (i < 1 || i > n || j < 1 || j > n || i == j) {
        finish(_pe, format("Invalid indices %d %d", i, j));
    }
}

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

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

    int n = inf.readInt();

    query_limit = (5LL * n) / 3 + 5;

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

    vector<int> a(n);

    if (!inf.seekEof()) {

        for (int i = 0; i < n; i++) {
            a[i] = inf.readInt();
        }
    } else {

        iota(a.begin(), a.end(), 1);
        for (int i = 0; i < n; i++) {

            int r = min(n - 1, i + 2);
            int j = rnd.next(i, r);
            swap(a[i], a[j]);
        }
    }

    cout << n << endl;

    log_metrics();

    while (true) {
        char type;

        if (!(cin >> type)) {
            finish(_pe, "Unexpected EOF (expected '?' or '!')");
        }

        if (type == '?') {
            int u, v;
            if (!(cin >> u >> v)) {
                finish(_pe, "Invalid query format");
            }

            validate_indices(u, v, n);

            queries++;

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

            int val_u = a[u - 1];
            int val_v = a[v - 1];

            if (val_u < val_v) {
                cout << "<" << endl;
            } else {
                cout << ">" << endl;
            }

        } else if (type == '!') {

            vector<int> guess(n);
            for (int i = 0; i < n; i++) {
                if (!(cin >> guess[i])) {
                    finish(_pe, "Invalid answer format (expected array)");
                }
            }

            bool ok = true;
            for (int i = 0; i < n; i++) {
                if (guess[i] != a[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                finish(_ok, format("Correct! queries=%lld", queries));
            } else {
                finish(_wa, format("Wrong answer. queries=%lld", queries));
            }

        } else {
            finish(_pe, format("Unknown token '%c'", 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);

    int strategy = 0;

    if (n == -1) {
        long long seed_val = atoll(argv[1]);

        if (seed_val == 1) {
            n = 5;
        } else if (seed_val == 2) {
            n = 1;
        } else if (seed_val == 3) {
            n = 2;
        } else if (seed_val == 4) {
            n = 3;
        } else if (seed_val == 5) {
            n = 30000; strategy = 1;
        } else if (seed_val == 6) {
            n = 30000; strategy = 2;
        } else if (seed_val == 7) {
            n = 30000;
        } else {

            n = rnd.next(1, 30000);
        }
    }

    if (mode == "adp") {
        cout << n << endl;
        return 0;
    }

    vector<int> a(n);
    iota(a.begin(), a.end(), 1);

    for (int i = 1; i <= n; i++) {
        int r = min(n, i + 2);
        int j = -1;

        if (strategy == 1) {
            j = i;
        } else if (strategy == 2) {
            j = r;
        } else {
            j = rnd.next(i, r);
        }

        swap(a[i - 1], a[j - 1]);
    }

    cout << n << endl;
    for (int i = 0; i < n; i++) {
        cout << a[i] << (i == n - 1 ? "" : " ");
    }
    cout << endl;

    return 0;
}