As you all know, the plum harvesting season is on! Little Milutin had his plums planted in an orchard that can be represented as an $n$ by $m$ matrix. While he was harvesting, he wrote the heights of all trees in a matrix of dimensions $n$ by $m$.

At night, when he has spare time, he likes to perform various statistics on his trees. This time, he is curious to find out the height of his lowest tree. So far, he has discovered some interesting properties of his orchard. There is one particular property that he thinks is useful for finding the tree with the smallest heigh.

Formally, let $L(i)$ be the leftmost tree with the smallest height in the $i$-th row of his orchard. He knows that $L(i) \le L(i+1)$ for all $1 \le i \le n - 1$. Moreover, if he takes a submatrix induced by any subset of rows and any subset of columns, $L(i) \le L(i+1)$ will hold for all $1 \le i \le n'-1$, where $n'$ is the number of rows in that submatrix.

Since the season is at its peak and he is short on time, he asks you to help him find the plum tree with minimal height.

Input

This problem is interactive.

The first line of input will contain two integers $n$ and $m$, representing the number of rows and the number of columns in Milutin's orchard. It is guaranteed that $1 \le n, m \le 10^6$.

The following lines will contain the answers to your queries.

Output

Once you know have found the minimum value $r$, you should print ! $r$ to the standard output.

Interaction

Your code is allowed to query for an entry $(i, j)$ of a matrix (i.e. get the height of the tree which is in the $i$-th row and $j$-th column). The query should be formatted as ? $i$ $j$, so that $1 \le i \le n$ and $1 \le j \le m$.

You may assume that the entries of the matrix will be integers between $1$ and $10^9$.

Your solution should use not more than $\mathbf{4 \cdot (n + m)}$ queries.

This is an interactive problem. You have to use a flush operation right after printing each line. For example, in C++ you should use the function fflush(stdout), in Java — System.out.flush(), in Pascal — flush(output) and in Python — sys.stdout.flush().

Example

Input

```
5 5
13 15 10 9 15
15 17 12 11 17
10 12 7 6 12
17 19 14 13 19
16 18 13 12 18
```

Output

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

static bool parseLongLongStrict(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '+') i++;
    if (i >= (int)s.size()) return false;
    if (s[i] == '-') return false;
    long long val = 0;
    for (; i < (int)s.size(); i++) {
        unsigned char c = (unsigned char)s[i];
        if (!isdigit(c)) return false;
        int d = s[i] - '0';
        if (val > (LLONG_MAX - d) / 10) return false;
        val = val * 10 + d;
    }
    out = val;
    return true;
}

static bool parseBoundedIntToken(const string& s, long long lo, long long hi, long long& out) {
    long long v;
    if (!parseLongLongStrict(s, v)) return false;
    if (v < lo || v > hi) return false;
    out = v;
    return true;
}

static struct _BumpTestlibLimits {
    _BumpTestlibLimits() {
        inf.maxFileSize = 512ULL * 1024ULL * 1024ULL;
    }
} _bumpTestlibLimits;

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

    int n = 0, m = 0;
    try {
        n = inf.readInt(1, 1000000, "n");
        m = inf.readInt(1, 1000000, "m");
    } catch (...) {
        query_limit = 0;
        log_metrics();
        quitf(_pe, "Invalid hidden input (failed to read n,m)");
    }

    query_limit = 4LL * ( (long long)n + (long long)m );
    log_metrics();

    long long nm = 1LL * n * m;
    vector<int> a;
    a.reserve((size_t)min<long long>(nm, 1000000LL));

    int globalMin = INT_MAX;
    try {
        a.assign((size_t)nm, 0);
        for (int i = 1; i <= n; i++) {
            long long base = 1LL * (i - 1) * m;
            for (int j = 1; j <= m; j++) {
                int v = inf.readInt(1, 1000000000, "a[i][j]");
                a[(size_t)(base + (j - 1))] = v;
                if (v < globalMin) globalMin = v;
            }
        }
    } catch (const bad_alloc&) {
        finish(_pe, "Interactor out of memory while storing matrix");
    } catch (...) {
        finish(_pe, "Invalid hidden input (failed to read full matrix)");
    }

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

    const long long hard_cap = max(200000LL, query_limit > (LLONG_MAX / 10) ? LLONG_MAX : 10LL * query_limit);

    while (true) {
        string cmd;
        if (!readToken(cmd)) {
            finish(_pe, "Unexpected EOF: contestant did not output final answer");
        }

        if (cmd == "?") {
            string si, sj;
            if (!readToken(si) || !readToken(sj)) {
                finish(_pe, "Malformed query: expected '? i j'");
            }
            long long i, j;
            if (!parseBoundedIntToken(si, 1, n, i) || !parseBoundedIntToken(sj, 1, m, j)) {
                finish(_pe, "Query indices out of bounds or not integers");
            }

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

            int ans = a[(size_t)((i - 1) * 1LL * m + (j - 1))];
            cout << ans << endl;
        } else if (cmd == "!") {
            string sr;
            if (!readToken(sr)) {
                finish(_pe, "Malformed answer: expected '! r'");
            }
            long long r;
            if (!parseBoundedIntToken(sr, 1, 1000000000LL, r)) {
                finish(_pe, "Answer is not a valid integer in [1,1e9]");
            }
            if ((int)r == globalMin) {
                finish(_ok, "Correct");
            } else {
                finish(_wa, "Wrong minimum");
            }
        } else {
            finish(_pe, "Unknown command (expected '?' or '!')");
        }
    }
}

#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 isIntegerToken(const string& s) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '-') {
        if ((int)s.size() == 1) return false;
        i = 1;
    }
    for (; i < (int)s.size(); i++) if (!isdigit((unsigned char)s[i])) return false;
    return true;
}

struct AdaptiveSchema {
    int n = 0, m = 0;
    int type = 0;
    int g = 0;
    vector<int> p;
    vector<long long> B, D;
    uint64_t baseSeed = 0x123456789abcdefULL;
};

static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15ULL;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL;
    x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL;
    return x ^ (x >> 31);
}

static long long noiseDet(const AdaptiveSchema& S, int i, int j) {

    uint64_t x = S.baseSeed;
    x ^= (uint64_t)i * 1000003ULL;
    x ^= (uint64_t)j * 10007ULL;
    x = splitmix64(x);
    return (long long)(x & 7ULL);
}

static long long valueAt(const AdaptiveSchema& S, int i, int j) {

    int idx = i - 1;
    int p = S.p[idx];
    long long minVal = S.B[idx] - S.D[idx];
    if (minVal < 1) minVal = 1;
    long long dist = llabs((long long)j - p);
    long long v = minVal + dist * dist * 5 + dist * 13 + noiseDet(S, i, j);

    if (j == p) v = minVal;
    if (j < p && v <= minVal) v = minVal + 1;

    if (i == S.g && j == S.p[S.g - 1]) v = 1;

    if (v < 1) v = 1;
    if (v > 1000000000LL) v = 1000000000LL - (v % 1000);
    if (v < 1) v = 1;
    return v;
}

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

    int n = 0, m = 0;
    if (inf.seekEof()) finish(_pe, "empty input");
    n = inf.readInt(1, 1000000, "n");
    m = inf.readInt(1, 1000000, "m");

    if (inf.seekEof()) finish(_pe, "no data after n m");

    string tok = inf.readToken();
    bool adaptive = false;
    int type = 0;

    if (isIntegerToken(tok)) {
        long long maybeTypeOrA11 = stoll(tok);
        if (maybeTypeOrA11 == 1) {

            adaptive = true;
            type = 1;
        } else {
            adaptive = false;
        }
    } else {
        finish(_pe, "unexpected token after n m");
    }

    query_limit = 4LL * ( (long long)n + (long long)m );
    log_metrics();
    long long hard_cap = max(200000LL, 10LL * query_limit);

    AdaptiveSchema S;
    vector<vector<int>> A;
    bool nonLoaded = false;

    if (adaptive) {

        if (inf.seekEof()) {
            adaptive = false;
        } else {
            int g = 0;
            try {
                g = inf.readInt(1, n, "g");
            } catch (...) {
                adaptive = false;
            }
            if (adaptive) {
                S.n = n; S.m = m; S.type = type; S.g = g;
                S.p.assign(n, 1);
                S.B.assign(n, 0);
                S.D.assign(n, 0);
                bool ok = true;
                for (int i = 1; i <= n; i++) {
                    if (inf.seekEof()) { ok = false; break; }
                    int pi;
                    long long Bi, Di;
                    try {
                        pi = inf.readInt(1, m, "p[i]");
                        Bi = inf.readLong(1LL, 1000000000LL, "B[i]");
                        Di = inf.readLong(0LL, 1000000000LL, "D[i]");
                    } catch (...) {
                        ok = false; break;
                    }
                    if (Di >= Bi) { ok = false; break; }
                    if (Bi - Di < 1) { ok = false; break; }
                    S.p[i-1] = pi;
                    S.B[i-1] = Bi;
                    S.D[i-1] = Di;
                }
                if (!ok) adaptive = false;
                else {

                    uint64_t h = 1469598103934665603ULL;
                    auto mix = [&](uint64_t x) {
                        h ^= x + 0x9e3779b97f4a7c15ULL + (h<<6) + (h>>2);
                    };
                    mix((uint64_t)n); mix((uint64_t)m); mix((uint64_t)type); mix((uint64_t)g);
                    for (int i = 0; i < n; i++) {
                        mix((uint64_t)S.p[i]);
                        mix((uint64_t)S.B[i]);
                        mix((uint64_t)S.D[i]);
                    }
                    S.baseSeed = splitmix64(h);
                }
            }
        }
    }

    if (!adaptive) {

        long long cells = 1LL * n * m;
        if (cells > 25000000LL) {
            finish(_pe, "non-adaptive matrix too large to store in interactor");
        }
        A.assign(n, vector<int>(m, 0));

        if (!isIntegerToken(tok)) finish(_pe, "invalid a11 token");
        long long a11 = stoll(tok);
        if (a11 < 1 || a11 > 1000000000LL) finish(_pe, "a11 out of range");
        A[0][0] = (int)a11;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (i==0 && j==0) continue;
                if (inf.seekEof()) finish(_pe, "not enough matrix entries");
                int v = inf.readInt(1, 1000000000, "a[i][j]");
                A[i][j] = v;
            }
        }
        nonLoaded = true;
    }

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

    auto getVal = [&](int i, int j)->long long{
        if (adaptive) return valueAt(S, i, j);
        else return A[i-1][j-1];
    };

    while (true) {
        string cmd;
        if (!(cin >> cmd)) {
            finish(_pe, "EOF from contestant");
        }
        if (cmd == "?") {
            long long i, j;
            if (!(cin >> i >> j)) finish(_pe, "bad query format");
            if (i < 1 || i > n || j < 1 || j > m) finish(_pe, "query indices out of range");

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

            long long ans = getVal((int)i, (int)j);
            cout << ans << "\n";
            cout.flush();
        } else if (cmd == "!") {
            long long r;
            if (!(cin >> r)) finish(_pe, "bad answer format");
            if (r < 1 || r > 1000000000LL) finish(_wa, "answer out of range");

            long long trueMin = LLONG_MAX;
            if (adaptive) {

                trueMin = 1;
                for (int i = 1; i <= n; i++) {
                    long long mv = S.B[i-1] - S.D[i-1];
                    if (mv < 1) mv = 1;

                    trueMin = min(trueMin, mv);
                }
            } else {
                for (int i = 0; i < n; i++)
                    for (int j = 0; j < m; j++)
                        trueMin = min(trueMin, (long long)A[i][j]);
            }

            if (r != trueMin) finish(_wa, "wrong minimum");
            finish(_ok, "ok");
        } else {
            finish(_pe, "unknown command");
        }
    }
}


F. New Year and Finding Roots

This is an interactive problem. In the interaction section below you will find the information about flushing the output.

The New Year tree of height *h* is a perfect binary tree with vertices numbered 1 through 2*h* - 1 in some order. In this problem we assume that *h* is at least 2. The drawing below shows one example New Year tree of height 3:

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

Polar bears love decorating the New Year tree and Limak is no exception. To decorate the tree, he must first find its root, i.e. a vertex with exactly two neighbours (assuming that *h* ≥ 2). It won't be easy because Limak is a little bear and he doesn't even see the whole tree. Can you help him?

There are *t* testcases. In each testcase, you should first read *h* from the input. Then you can ask at most 16 questions of format "? x" (without quotes), where *x* is an integer between 1 and 2*h* - 1, inclusive. As a reply you will get the list of neighbours of vertex *x* (more details in the "Interaction" section below). For example, for a tree on the drawing above after asking "? 1" you would get a response with 3 neighbours: 4, 5 and 7. Your goal is to find the index of the root *y* and print it in the format "! y". You will be able to read *h* for a next testcase only after printing the answer in a previous testcase and flushing the output.

Each tree is fixed from the beginning and it doesn't change during your questions.

Input

The first line of the input contains a single integer *t* (1 ≤ *t* ≤ 500) — the number of testcases.

At the beginning of each testcase you should read from the input a single integer *h* (2 ≤ *h* ≤ 7) — the height of the tree. You can't read the value of *h* in a next testcase until you answer a previous testcase.

Interaction

To ask a question about neighbours of vertex *x*, print "? x" (without quotes) on a separate line. Note, you must print an end-of-line character after the last character of the line and flush your output to get a response.

The response will consist of two lines. The first line will contain a single integer *k* (1 ≤ *k* ≤ 3) — the number of neighbours of vertex *x*. The second line will contain *k* distinct integers *t*1, ..., *t**k* (1 ≤ *t*1 < ... < *t**k* ≤ 2*h* - 1) — indices of neighbours of vertex *x*, gives in the increasing order.

After asking at most 16 questions you have to say *y* — the index of the root. Print "! y" (without quotes) and an end-of-line character, and flush the output.

Each tree is fixed from the beginning and it doesn't change during your questions.

You can get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output.

To flush you can use (just printing a query/answer 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.

In any moment if the program reads *h* = 0 or *k* = 0 it should immediately terminate normally (for example, calling exit(0)). It means that the system detected incorrect request/output from your program and printed 0 because if can't process your requests anymore. In this case you'll receive verdict "Wrong Answer", but if you ignore case *h* = 0 or *k* = 0 it could lead to "Runtime Error", "Time/Memory limit exceeded" or any other verdict because your program could read a trash from the closed input stream.

Examples

Input

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

Output

```
? 1
? 5
? 6
! 5
```

Input

```
2
2
1
3
2
1 2
2
1 2
4
3
3 12 13
```

Output

```
? 1
? 3
? 3
! 3
? 6
! 1
```

Note

In the first sample, a tree corresponds to the drawing from the statement.

In the second sample, there are two two testcases. A tree in the first testcase has height 2 and thus 3 vertices. A tree in the second testcase has height 4 and thus 15 vertices. You can see both trees on the drawing below.

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

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

using namespace std;

static long long queries_metric = 0;

static long long query_limit_metric = 16;

static void log_metrics() {
    try {
        tout << "queries=" << queries_metric << endl;
        tout << "query_limit=" << query_limit_metric << 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 t = inf.readInt();

    cout << t << endl;

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

        int h = inf.readInt();
        int n = (1 << h) - 1;

        vector<vector<int>> adj(n + 1);
        for (int j = 0; j < n - 1; j++) {
            int u = inf.readInt();
            int v = inf.readInt();
            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        int real_root = -1;
        for (int u = 1; u <= n; u++) {
            if (adj[u].size() == 2) {
                real_root = u;
                break;
            }
        }

        if (real_root == -1) {
            finish(_fail, "Generator error: No root of degree 2 found in the tree.");
        }

        cout << h << endl;

        long long current_case_queries = 0;

        while (true) {
            string token;
            if (!(cin >> token)) {
                finish(_wa, "Unexpected EOF (contestant output ended prematurely)");
            }

            if (token == "!") {

                int y;
                if (!(cin >> y)) {
                    finish(_wa, "Expected integer answer after '!'");
                }

                if (y == real_root) {

                    break;
                } else {
                    finish(_wa, format("Wrong answer: guessed %d, expected %d", y, real_root));
                }
            } else {

                int x = -1;
                if (token == "?") {
                    if (!(cin >> x)) {
                        finish(_wa, "Expected integer query index after '?'");
                    }
                } else {

                    try {
                        size_t pos;
                        x = stoi(token, &pos);
                        if (pos != token.size()) {
                            finish(_wa, "Invalid query token (garbage after integer)");
                        }
                    } catch (...) {
                        finish(_wa, format("Invalid token '%s': expected '?', '!', or integer", token.c_str()));
                    }
                }

                if (x < 1 || x > n) {
                    finish(_wa, format("Query index %d out of bounds [1, %d]", x, n));
                }

                current_case_queries++;
                queries_metric = max(queries_metric, current_case_queries);

                if (current_case_queries % 10 == 0) {
                    log_metrics();
                }

                if (current_case_queries > 200) {
                    finish(_pe, "Hard query limit exceeded (200) for a single testcase");
                }

                int k = (int)adj[x].size();
                sort(adj[x].begin(), adj[x].end());

                cout << k << endl;
                for (int j = 0; j < k; j++) {
                    cout << adj[x][j] << (j == k - 1 ? "" : " ");
                }
                cout << endl;
            }
        }
    }

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

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

using namespace std;

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

const long long HARD_CAP = 20000;

static void log_metrics() {
    try {
        tout << "queries=" << queries << endl;

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

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

vector<int> get_neighbors_pos(int pos, int h) {
    vector<int> neis;
    if (pos > 1) neis.push_back(pos / 2);
    int left = pos * 2;
    int right = pos * 2 + 1;
    int max_node = (1 << h) - 1;
    if (left <= max_node) neis.push_back(left);
    if (right <= max_node) neis.push_back(right);
    sort(neis.begin(), neis.end());
    return neis;
}

vector<int> input_data;
size_t input_ptr = 0;

int read_int_from_buffer() {
    if (input_ptr >= input_data.size()) __testlib_fail("Input exhausted unexpectedly");
    return input_data[input_ptr++];
}

struct AdaptiveState {
    int h;
    int n;
    map<int, int> node_to_pos;
    map<int, int> pos_to_node;
    set<int> used_labels;
    set<int> used_positions;

    void init(int _h) {
        h = _h;
        n = (1 << h) - 1;
        node_to_pos.clear();
        pos_to_node.clear();
        used_labels.clear();
        used_positions.clear();
    }

    int get_pos(int label) {
        if (node_to_pos.count(label)) return node_to_pos[label];

        vector<int> candidates;
        for (int p = 1; p <= n; ++p) {
            if (used_positions.find(p) == used_positions.end()) {
                candidates.push_back(p);
            }
        }

        if (candidates.empty()) __testlib_fail("No positions left (internal error)");

        vector<int> non_root;
        for (int c : candidates) {
            if (c != 1) non_root.push_back(c);
        }

        int chosen = -1;
        if (!non_root.empty()) {
            chosen = non_root[rnd.next(0, (int)non_root.size() - 1)];
        } else {

            chosen = 1;
        }

        assign(label, chosen);
        return chosen;
    }

    void assign(int label, int pos) {
        if (node_to_pos.count(label) && node_to_pos[label] != pos)
            __testlib_fail("Inconsistent assignment");
        if (pos_to_node.count(pos) && pos_to_node[pos] != label)
            __testlib_fail("Inconsistent assignment");

        node_to_pos[label] = pos;
        pos_to_node[pos] = label;
        used_labels.insert(label);
        used_positions.insert(pos);
    }

    int ensure_label(int n_pos) {
        if (pos_to_node.count(n_pos)) return pos_to_node[n_pos];

        vector<int> available;
        for (int i = 1; i <= n; ++i) {
            if (used_labels.find(i) == used_labels.end()) {
                available.push_back(i);
            }
        }
        if (available.empty()) __testlib_fail("No labels left (internal error)");

        int lbl = available[rnd.next(0, (int)available.size() - 1)];
        assign(lbl, n_pos);
        return lbl;
    }
};

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

    while (!inf.seekEof()) {
        input_data.push_back(inf.readInt());
    }

    if (input_data.empty()) __testlib_fail("Empty input");

    int t = input_data[input_ptr++];

    bool adaptive_mode = (input_data.size() == (size_t)(1 + t));

    cout << t << endl;

    for (int i = 0; i < t; ++i) {
        int h = read_int_from_buffer();
        int n = (1 << h) - 1;
        cout << h << endl;

        vector<vector<int>> adj;
        int fixed_root = -1;

        AdaptiveState adpState;

        if (adaptive_mode) {
            adpState.init(h);
        } else {

            adj.assign(n + 1, vector<int>());

            for (int k = 0; k < n - 1; ++k) {
                int u = read_int_from_buffer();
                int v = read_int_from_buffer();
                adj[u].push_back(v);
                adj[v].push_back(u);
            }

            for (int u = 1; u <= n; ++u) {
                if (adj[u].size() == 2) {
                    fixed_root = u;
                    break;
                }
            }
            if (fixed_root == -1) {

                finish(_wa, "Invalid test case: no root found in fixed graph");
            }

            for(auto& row : adj) sort(row.begin(), row.end());
        }

        int local_queries = 0;
        bool solved = false;

        while (true) {

            string type;
            if (!(cin >> type)) finish(_wa, "Unexpected EOF from contestant");

            if (type == "!") {
                int ans;
                if (!(cin >> ans)) finish(_wa, "Expected answer integer");

                if (adaptive_mode) {

                    if (adpState.pos_to_node.count(1)) {

                        int actual_root = adpState.pos_to_node[1];
                        if (ans != actual_root) {
                            finish(_wa, format("Wrong answer. Expected %d, found %d", actual_root, ans));
                        }
                    } else {

                        if (adpState.node_to_pos.count(ans)) {
                            finish(_wa, format("Wrong answer. Node %d is at position %d, not root", ans, adpState.node_to_pos[ans]));
                        }

                        int assigned_count = adpState.used_labels.size();
                        if (assigned_count < n) {

                             finish(_wa, "Wrong answer. You guessed an unvisited node, but it wasn't uniquely determined.");
                        } else {

                        }
                    }
                } else {

                    if (ans != fixed_root) {
                        finish(_wa, format("Wrong answer. Expected %d, found %d", fixed_root, ans));
                    }
                }

                solved = true;
                break;
            } else if (type == "?") {
                int u;
                if (!(cin >> u)) finish(_wa, "Expected query integer");

                if (u < 1 || u > n) finish(_wa, format("Invalid query vertex %d (n=%d)", u, n));

                queries++;
                local_queries++;
                log_metrics();

                if (local_queries > 16) {
                    finish(_wa, "Query limit exceeded (16 per testcase)");
                }
                if (queries > HARD_CAP) {
                    finish(_pe, "Hard query limit exceeded");
                }

                vector<int> neighbors;
                if (adaptive_mode) {

                    int pos = adpState.get_pos(u);

                    vector<int> n_positions = get_neighbors_pos(pos, h);

                    for (int np : n_positions) {
                        neighbors.push_back(adpState.ensure_label(np));
                    }
                    sort(neighbors.begin(), neighbors.end());
                } else {
                    neighbors = adj[u];
                }

                cout << neighbors.size();
                for (int v : neighbors) cout << " " << v;
                cout << endl;

            } else {
                finish(_wa, "Invalid token type: " + type);
            }
        }
    }

    finish(_ok, "All test cases passed");
    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 t_arg = opt<int>("t", -1);

    int h_arg = opt<int>("h", -1);

    long long seed_val = 0;
    if (argc > 1) {
        seed_val = atoll(argv[1]);
    }

    int t = (t_arg != -1) ? t_arg : 1;

    cout << t << "\n";

    for (int i = 0; i < t; ++i) {
        int h;
        if (h_arg != -1) {
            h = h_arg;
        } else {

            if (seed_val == 1) h = 2;
            else if (seed_val == 2) h = 3;
            else if (seed_val == 3) h = 7;
            else {

                int r = rnd.next(1, 100);
                if (r <= 60) h = 7;
                else if (r <= 85) h = 6;
                else h = rnd.next(2, 5);
            }
        }

        cout << h << "\n";

        if (mode == "non") {

            int n = (1 << h) - 1;
            vector<pair<int, int>> edges;

            int internal_nodes = (1 << (h - 1)) - 1;
            for (int u = 1; u <= internal_nodes; ++u) {
                edges.push_back({u, 2 * u});
                edges.push_back({u, 2 * u + 1});
            }

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

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

            for (const auto& edge : edges) {
                cout << p[edge.first] << " " << p[edge.second] << "\n";
            }
        }

    }

    return 0;
}


This problem is interactive.

We have hidden an array $a$ of $n$ pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.

This device can answer queries of the following form: in response to the positions of $k$ different elements of the array, it will return the position and value of the $m$-th among them in the ascending order.

Unfortunately, the instruction for the device was lost during delivery. However, you remember $k$, but don't remember $m$. Your task is to find $m$ using queries to this device.

You can ask not more than $n$ queries.

Note that the array $a$ and number $m$ are fixed before the start of the interaction and don't depend on your queries. In other words, interactor is not adaptive.

Note that you don't have to minimize the number of queries, and you don't need to guess array $a$. You just have to guess $m$.

Input

The first line contains two integers $n$ and $k$ ($1\le k < n \le 500$) — the length of the array and the number of the elements in the query.

It is guaranteed that number $m$ satisfies $1\le m \le k$, elements $a_1, a_2, \dots, a_n$ of the array satisfy $0\le a_i \le 10^9$, and all of them are different.

Interaction

You begin the interaction by reading $n$ and $k$.

To ask a question about elements on positions $x_1, x_2, \dots, x_k$, in a separate line output

$?$ $x_1$ $x_2$ $x_3$ ... $x_k$

Numbers in the query have to satisfy $1 \le x_i \le n$, and all $x_i$ have to be different. Don't forget to 'flush', to get the answer.

In response, you will receive two integers $pos$ and $a_{pos}$ — the position in the array $a$ of the $m$-th in ascending order element among $a_{x_1}, a_{x_2}, \dots, a_{x_k}$, and the element on this position.

In case your query is invalid or you asked more than $n$ 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 determine $m$, output

$!$ $m$

After printing a query 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

```
4 3
4 9
4 9
4 9
1 2
```

Output

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

Note

In the example, $n = 4$, $k = 3$, $m = 3$, $a = [2, 0, 1, 9]$.

#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& tok) {
    return (cin >> tok) ? true : false;
}

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[0] == '-') {
        neg = true;
        i = 1;
        if ((int)s.size() == 1) return false;
    }
    long long val = 0;
    for (; i < (int)s.size(); ++i) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        val = val * 10 + (c - '0');
        if (val > (1LL << 62)) return false;
    }
    x = neg ? -val : val;
    return true;
}

static void replyInvalidQueryAndDie(const string& why) {
    cout << -1 << endl;
    cout.flush();
    finish(_wa, why);
}

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

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    try {
        int n = inf.readInt(1, 500, "n");
        int k = inf.readInt(1, n - 1, "k");
        int m = inf.readInt(1, k, "m");

        vector<long long> a(n + 1);
        for (int i = 1; i <= n; ++i) {
            a[i] = inf.readLong(0LL, 1000000000LL, "a[i]");
        }

        query_limit = n;
        log_metrics();

        cout << n << " " << k << endl;
        cout.flush();

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

        while (true) {
            string cmd;
            if (!readToken(cmd)) {
                finish(_pe, "unexpected EOF from contestant");
            }

            if (cmd == "?") {
                if (queries >= hard_cap) finish(_pe, "hard cap exceeded");

                vector<int> xs;
                xs.reserve(k);
                vector<char> seen(n + 1, 0);

                for (int i = 0; i < k; ++i) {
                    long long xi_ll;
                    if (!readIntFromCin(xi_ll)) {
                        replyInvalidQueryAndDie("malformed index in query");
                    }
                    if (xi_ll < 1 || xi_ll > n) {
                        replyInvalidQueryAndDie("index out of range in query");
                    }
                    int xi = (int)xi_ll;
                    if (seen[xi]) {
                        replyInvalidQueryAndDie("duplicate index in query");
                    }
                    seen[xi] = 1;
                    xs.push_back(xi);
                }

                ++queries;
                log_metrics();

                vector<pair<long long, int>> vals;
                vals.reserve(k);
                for (int pos : xs) vals.push_back({a[pos], pos});
                sort(vals.begin(), vals.end());

                int ansPos = vals[m - 1].second;
                long long ansVal = vals[m - 1].first;

                cout << ansPos << " " << ansVal << endl;
                cout.flush();
            } else if (cmd == "!") {
                long long guess_ll;
                if (!readIntFromCin(guess_ll)) {
                    finish(_pe, "malformed final answer");
                }
                if (guess_ll < 1 || guess_ll > k) {
                    finish(_wa, "final answer out of range");
                }
                int guess = (int)guess_ll;
                if (guess == m) finish(_ok, "correct");
                finish(_wa, "wrong m");
            } else {
                if (cmd == "-1") finish(_pe, "contestant printed -1");
                finish(_pe, "unknown command token");
            }
        }
    } 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;

template <class T>
static void shuffleVec(vector<T>& v) {
    for (int i = (int)v.size() - 1; i > 0; --i) {
        int j = rnd.next(0, i);
        swap(v[i], v[j]);
    }
}

static vector<int> buildArrayByRanks(int n, const vector<int>& rankAtPos) {
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {

        int base = rankAtPos[i] * 1000000;
        int add = rnd.next(0, 999999);
        a[i] = base + add;
    }
    return a;
}

static void genStructured(int n, int k, int m, vector<int>& outRankAtPos) {
    outRankAtPos.assign(n + 1, -1);

    if (k == 1) {

        int r = (n + 1) / 2;
        outRankAtPos[1] = r;
        int cur = 1;
        for (int x = 1; x <= n; ++x) {
            if (x == r) continue;
            ++cur;
            outRankAtPos[cur] = x;
        }
        return;
    }

    m = max(1, min(m, k));

    int minPivot = m;
    int maxPivot = n - (k - m);
    if (minPivot > maxPivot) {

        minPivot = maxPivot = max(1, min(n, m));
    }

    int mid = (n + 1) / 2;
    int pivotRank;

    if (mid < minPivot) pivotRank = minPivot;
    else if (mid > maxPivot) pivotRank = maxPivot;
    else pivotRank = mid;

    if (maxPivot - minPivot >= 4) {
        int delta = rnd.next(-2, 2);
        pivotRank = max(minPivot, min(maxPivot, pivotRank + delta));
    }

    vector<int> less, greater;
    less.reserve(max(0, pivotRank - 1));
    greater.reserve(max(0, n - pivotRank));

    for (int x = 1; x < pivotRank; ++x) less.push_back(x);
    for (int x = pivotRank + 1; x <= n; ++x) greater.push_back(x);

    shuffleVec(less);
    shuffleVec(greater);

    int needLess = m - 1;
    int needGreater = k - m;

    if (needLess > (int)less.size()) {
        int deficit = needLess - (int)less.size();
        needLess -= deficit;
        needGreater += deficit;
        needGreater = min(needGreater, (int)greater.size());
    }
    if (needGreater > (int)greater.size()) {
        int deficit = needGreater - (int)greater.size();
        needGreater -= deficit;
        needLess += deficit;
        needLess = min(needLess, (int)less.size());
    }

    vector<int> firstK;
    firstK.reserve(k);

    for (int i = 0; i < needLess; ++i) firstK.push_back(less[i]);
    firstK.push_back(pivotRank);
    for (int i = 0; i < needGreater; ++i) firstK.push_back(greater[i]);

    while ((int)firstK.size() < k) {

        if ((int)greater.size() > needGreater) {
            firstK.push_back(greater[needGreater]);
            ++needGreater;
        } else if ((int)less.size() > needLess) {
            firstK.push_back(less[needLess]);
            ++needLess;
        } else {
            break;
        }
    }

    shuffleVec(firstK);

    vector<int> used(n + 1, 0);
    for (int x : firstK) used[x] = 1;

    vector<int> rest;
    rest.reserve(n - k);
    for (int x = 1; x <= n; ++x) if (!used[x]) rest.push_back(x);
    shuffleVec(rest);

    for (int i = 1; i <= k; ++i) outRankAtPos[i] = firstK[i - 1];
    for (int i = k + 1; i <= n; ++i) outRankAtPos[i] = rest[i - (k + 1)];
}

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

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

    long long seed = 0;
    if (argc >= 2) {

        seed = atoll(argv[1]);
    }

    int n = opt<int>("n", 500);
    n = max(2, min(500, n));

    int kOpt = opt<int>("k", 0);
    int k;
    if (kOpt != 0) {
        k = kOpt;
    } else {

        if (seed >= 4 && (seed % 5 == 0)) k = 2;
        else if (seed >= 4 && (seed % 7 == 0)) k = 3;
        else k = (n / 2);
    }
    k = max(1, min(n - 1, k));

    int mOpt = opt<int>("m", 0);
    int m;
    if (mOpt != 0) {
        m = mOpt;
    } else {
        if (seed == 1) m = 1;
        else if (seed == 2) m = k;
        else if (seed == 3) m = max(1, min(k, (k + 1) / 2));
        else {
            if (k == 1) m = 1;
            else {

                int t = rnd.next(0, 9);
                if (t == 0) m = 1;
                else if (t == 1) m = k;
                else {
                    int mid = (k + 1) / 2;
                    int delta = (k >= 6 ? rnd.next(-2, 2) : rnd.next(-1, 1));
                    m = max(1, min(k, mid + delta));
                    if (k >= 3 && m == 1) m = 2;
                    if (k >= 3 && m == k) m = k - 1;
                }
            }
        }
    }
    m = max(1, min(k, m));

    vector<int> a;
    if (seed == 1) {
        n = 2; k = 1; m = 1;
        a.assign(n + 1, 0);
        a[1] = 0;
        a[2] = 1;
    } else if (seed == 2) {
        n = 500; k = 499; m = 499;
        a.assign(n + 1, 0);
        for (int i = 1; i <= n; ++i) a[i] = i;
    } else if (seed == 3) {
        n = 500; k = 250; m = 125;
        vector<int> rankAtPos;
        genStructured(n, k, m, rankAtPos);
        a = buildArrayByRanks(n, rankAtPos);
    } else {

        vector<int> rankAtPos;
        genStructured(n, k, m, rankAtPos);
        a = buildArrayByRanks(n, rankAtPos);
    }

    if (mode != "non" && mode != "adp") {
        quitf(_fail, "unknown mode: %s", mode.c_str());
    }

    cout << n << " " << k << "\n";
    cout << m << "\n";
    if (mode == "non") {
        for (int i = 1; i <= n; ++i) {
            if (i > 1) cout << ' ';
            cout << a[i];
        }
        cout << "\n";
    }
    return 0;
}


This is an interactive problem.

Kevin has $n$ classmates, numbered $1, 2, \ldots, n$. Any two of them may either be friends or not friends.

Kevin wants to select $2k$ classmates to form $k$ teams, where each team contains exactly $2$ people. Each person can belong to at most one team.

Let $u_i$ and $v_i$ be two people in the $i$-th team. To avoid potential conflicts during team formation, the team members must satisfy one of the following two conditions:

* For all $i$ ($1\leq i \leq k$), classmate $u_i$ and $v_i$ are friends.
* For all $i$ ($1\leq i \leq k$), classmate $u_i$ and $v_i$ are not friends.

Kevin wants to determine the maximum $k$ such that, regardless of the friendship relationships among the $n$ people, he can always find $2k$ people to form the teams. After that, he needs to form $k$ teams. But asking whether two classmates are friends is awkward, so Kevin wants to achieve this while asking about the friendship status of no more than $n$ pairs of classmates.

The interactor is adaptive. It means that the hidden relationship between classmates is not fixed before the interaction and will change during the interaction.

Interaction

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 first line of each test case contains one positive integer $n$ ($2\leq n \leq 10^5$) — the number of classmates.

First, you should output an integer $k$ ($1\leq k\leq \frac{n}2$) — the maximum number of teams you can form.

You can make queries in the following way — print one line of the form $?\;u\;v$ where $1\leq u\neq v \leq n$. After that, read a single integer: $0$ or $1$ indicating whether they are friends. $1$ means they are friends while $0$ means not.

If you want to print the answer, output $!\;u_1\;v_1\;u_2\;v_2\;\ldots\;u_k\;v_k$. You should output exactly $2k$ distinct numbers. Then, the interaction continues with the next test case.

You can make at most $n$ queries. Printing the answer does not count towards the number of queries made.

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

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.

Example

Input

```
2
3

1

5

1

0

1

0

0
```

Output

```
1
? 1 2

! 1 2

2
? 1 2

? 3 4

? 3 5

? 1 3

? 2 4

! 1 2 3 5
```

Note

In the first test case:

Kevin claims he can form $1$ team regardless of the friendship relationships among the $3$ people.

Kevin asks about the friendship relationship between people $1$ and $2$. The jury responds that they are friends.

Kevin answers that he can form a team with people $1$ and $2$.

In the second test case:

Kevin claims he can form $2$ teams regardless of the friendship relationships among the $5$ people.

Kevin asks about the friendship relationship between people $(1, 2), (3, 4), (3, 5), (1, 3), (2, 4)$. The jury responds with $1, 0, 1, 0, 0$.

Kevin answers that he can form two teams with people $(1, 2)$ and $(3, 5)$.

It is also possible to form two teams with people $(1, 3)$ and $(2, 4)$, since they are both not friends.

#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 isDigits(const string& s) {
    if (s.empty()) return false;
    for (char c : s) if (c < '0' || c > '9') return false;
    return true;
}

static long long parseLLNonNeg(const string& s, const string& what) {
    if (!isDigits(s)) finish(_pe, "Malformed integer token for " + what);
    if (s.size() > 19) finish(_pe, "Integer token too long for " + what);
    long long x = 0;
    for (char c : s) {
        int d = c - '0';
        if (x > (LLONG_MAX - d) / 10) finish(_pe, "Integer overflow for " + what);
        x = x * 10 + d;
    }
    return x;
}

static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15ULL;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL;
    x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL;
    return x ^ (x >> 31);
}

static int friendship(int u, int v, uint64_t salt) {
    if (u > v) swap(u, v);
    uint64_t x = salt;
    x ^= (uint64_t)u * 0x9e3779b97f4a7c15ULL;
    x ^= (uint64_t)v * 0xbf58476d1ce4e5b9ULL;
    return (int)(splitmix64(x) & 1ULL);
}

static bool readToken(string& out) {
    out.clear();
    if (!(cin >> out)) return false;
    return true;
}

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

    int t = 0;
    try {
        t = inf.readInt(1, 10000, "t");
    } catch (...) {
        finish(_pe, "Failed to read t from hidden input");
    }

    vector<int> ns(t);
    vector<uint64_t> salts(t);

    long long totalN = 0;
    for (int i = 0; i < t; i++) {
        int n = 0;
        try {
            n = inf.readInt(2, 100000, "n");
        } catch (...) {
            finish(_pe, "Failed to read n from hidden input");
        }
        ns[i] = n;
        totalN += n;

        long long saltSigned = 0;
        try {
            saltSigned = inf.readLong();
        } catch (...) {

            saltSigned = 0;
        }
        salts[i] = (uint64_t)saltSigned;
    }

    query_limit = totalN;
    log_metrics();

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

    cout << t << endl;

    for (int tc = 0; tc < t; tc++) {
        int n = ns[tc];
        uint64_t salt = salts[tc];

        cout << n << endl;

        string tok;
        if (!readToken(tok)) finish(_pe, "EOF while expecting k");
        long long k = parseLLNonNeg(tok, "k");

        long long kmax = (n + 1) / 3;
        if (k < 1 || k > n / 2) finish(_wa, "k out of allowed range");
        if (k != kmax) finish(_wa, "Incorrect k");

        while (true) {
            string cmd;
            if (!readToken(cmd)) finish(_pe, "EOF while expecting command");

            if (cmd == "?") {
                string su, sv;
                if (!readToken(su) || !readToken(sv)) finish(_pe, "EOF in query");
                long long u = parseLLNonNeg(su, "u");
                long long v = parseLLNonNeg(sv, "v");
                if (u < 1 || u > n || v < 1 || v > n || u == v) finish(_pe, "Invalid query indices");

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

                int ans = friendship((int)u, (int)v, salt);
                cout << ans << endl;
            } else if (cmd == "!") {
                vector<int> a(2 * (size_t)k);
                vector<char> used(n + 1, 0);

                for (long long i = 0; i < 2 * k; i++) {
                    string sx;
                    if (!readToken(sx)) finish(_pe, "EOF in answer");
                    long long x = parseLLNonNeg(sx, "answer vertex");
                    if (x < 1 || x > n) finish(_wa, "Answer vertex out of range");
                    if (used[(int)x]) finish(_wa, "Duplicate vertex in answer");
                    used[(int)x] = 1;
                    a[(size_t)i] = (int)x;
                }

                int base = friendship(a[0], a[1], salt);
                for (long long i = 0; i < k; i++) {
                    int u = a[(size_t)(2 * i)];
                    int v = a[(size_t)(2 * i + 1)];
                    if (u == v) finish(_wa, "Pair has identical vertices");
                    int cur = friendship(u, v, salt);
                    if (cur != base) finish(_wa, "Pairs are not all the same type (friends vs not friends)");
                }
                break;
            } else {
                finish(_pe, "Unknown command token");
            }
        }
    }

    string extra;
    if (readToken(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';
    } catch (...) {

    }
}

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

static bool isDigits(const string& s) {
    if (s.empty()) return false;
    for (char c : s) if (c < '0' || c > '9') return false;
    return true;
}

static long long parseLLStrict(const string& s, bool& ok) {
    ok = false;
    if (!isDigits(s)) return 0;
    long long x = 0;
    for (char c : s) {
        int d = c - '0';
        if (x > (LLONG_MAX - d) / 10) return 0;
        x = x * 10 + d;
    }
    ok = true;
    return x;
}

static long long readLLFromCin(const char* what) {
    string tok;
    if (!(cin >> tok)) finish(_pe, string("unexpected EOF while reading ") + what);
    bool ok = false;
    long long x = parseLLStrict(tok, ok);
    if (!ok) finish(_pe, string("invalid integer token for ") + what);
    return x;
}

static uint64_t packPair(int u, int v) {
    if (u > v) swap(u, v);
    return (uint64_t)(uint32_t)u << 32 | (uint32_t)v;
}

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

    int t = inf.readInt(1, 10000, "t");
    vector<int> ns(t);
    vector<int> kmax(t);

    long long sumN = 0;
    for (int i = 0; i < t; i++) {
        int n = inf.readInt(2, 100000, "n");
        ns[i] = n;
        sumN += n;
        kmax[i] = (n + 1) / 3;
    }

    query_limit = sumN;
    log_metrics();

    cout << t << '\n';
    for (int i = 0; i < t; i++) cout << ns[i] << '\n';
    cout.flush();

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

    for (int tc = 0; tc < t; tc++) {
        int n = ns[tc];
        int expectedK = kmax[tc];

        long long k_ll = readLLFromCin("k");
        if (k_ll < 1 || k_ll > n / 2) finish(_wa, "k out of allowed range");
        if ((int)k_ll != expectedK) finish(_wa, "k is not the maximum guaranteed value");
        int k = (int)k_ll;

        unordered_map<uint64_t, int> known;
        known.reserve((size_t)min<long long>(hard_cap, (long long)n * 2 + 16));

        while (true) {
            string cmd;
            if (!(cin >> cmd)) finish(_pe, "unexpected EOF while reading command");

            if (cmd == "?") {
                long long u_ll = readLLFromCin("u");
                long long v_ll = readLLFromCin("v");
                if (u_ll < 1 || u_ll > n || v_ll < 1 || v_ll > n) finish(_wa, "query vertex out of range");
                if (u_ll == v_ll) finish(_wa, "query with identical vertices");
                int u = (int)u_ll, v = (int)v_ll;

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

                uint64_t key = packPair(u, v);
                auto it = known.find(key);
                int ans = 0;
                if (it == known.end()) known.emplace(key, ans);
                else ans = it->second;

                cout << ans << '\n';
                cout.flush();
            } else if (cmd == "!") {
                vector<int> out;
                out.reserve(2 * k);
                for (int i = 0; i < 2 * k; i++) {
                    long long x_ll = readLLFromCin("answer vertex");
                    if (x_ll < 1 || x_ll > n) finish(_wa, "answer vertex out of range");
                    out.push_back((int)x_ll);
                }

                vector<int> seen(n + 1, 0);
                for (int x : out) {
                    if (seen[x]) finish(_wa, "duplicate vertex in answer");
                    seen[x] = 1;
                }
                for (int i = 0; i < 2 * k; i += 2) {
                    if (out[i] == out[i + 1]) finish(_wa, "pair contains identical vertices");
                }

                if (k == 1) {
                    break;
                }

                int common = -1;
                for (int i = 0; i < 2 * k; i += 2) {
                    int u = out[i], v = out[i + 1];
                    uint64_t key = packPair(u, v);
                    auto it = known.find(key);
                    if (it == known.end()) finish(_wa, "answer uses unqueried pair (not forced in adaptive setting)");
                    int val = it->second;
                    if (common == -1) common = val;
                    else if (common != val) finish(_wa, "answer pairs are not all friends or all non-friends");
                }

                break;
            } else {
                finish(_pe, "unknown command token");
            }
        }
    }

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

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

static long long parseSeedArg(int argc, char** argv) {
    if (argc <= 1) return 1;
    const char* s = argv[1];
    bool neg = false;
    if (*s == '-') {
        neg = true;
        ++s;
    }
    long long x = 0;
    while (*s) {
        if (*s >= '0' && *s <= '9') x = x * 10 + (*s - '0');
        ++s;
    }
    return neg ? -x : x;
}

static int clampN(int n, int maxn) {
    n = max(2, n);
    n = min(maxn, n);
    return n;
}

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

    string mode = opt<string>("mode", "non");
    int maxn = opt<int>("maxn", 100000);
    int nOverride = opt<int>("n", -1);
    long long saltOverride = opt<long long>("salt", LLONG_MIN);

    long long seedArg = parseSeedArg(argc, argv);

    int n = 0;
    if (nOverride != -1) {
        n = clampN(nOverride, maxn);
    } else if (seedArg == 1) {
        n = 2;
    } else if (seedArg == 2) {
        n = 5;
    } else if (seedArg == 3) {
        n = maxn;
    } else {
        int roll = rnd.next(1, 100);
        if (roll <= 70) {
            n = maxn - rnd.next(0, min(10, maxn - 2));
        } else if (roll <= 90) {
            int lo = max(2, maxn - 5000);
            n = rnd.next(lo, maxn);
        } else {
            n = rnd.next(2, maxn);
        }
        n = clampN(n, maxn);

        if (n >= 10 && rnd.next(1, 100) <= 65) n = max(2, n - (n % 2));
        if (n >= 11 && rnd.next(1, 100) <= 35) n = max(3, n - ((n % 2) == 0));
        n = clampN(n, maxn);
    }

    cout << 1 << "\n";

    if (mode == "adp") {

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

    if (mode == "non") {

        long long salt;
        if (saltOverride != LLONG_MIN) {
            salt = saltOverride;
        } else if (seedArg == 1) {
            salt = 0;
        } else if (seedArg == 2) {
            salt = 1;
        } else if (seedArg == 3) {
            salt = 9223372036854775783LL;
        } else {
            long long hi = rnd.next(0LL, (1LL << 30) - 1);
            long long lo = rnd.next(0LL, (1LL << 32) - 1);
            salt = (hi << 32) ^ lo;
            salt ^= (seedArg << 1);
            if (salt == LLONG_MIN) salt = 0;
        }

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

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


You are tasked with creating a secret sequence of integers that is difficult to guess. The sequence is subject to the following constraints:

• The first number in the sequence must be 0.
• The last number in the sequence must be 100 000.
• Each number in the sequence must be either 1 or 2 greater than the one preceding it. At first, all you need to reveal is the length of the sequence.
Then, an adversary will guess the numbers in the sequence one at a time.

• If the guessed number is in your sequence, you must reveal exactly where in the sequence it appears. • If the guessed number is not in your sequence, you must simply reveal that it is not in the sequence. This is considered a “miss”.

Note that because you are not forced to write down the sequence in advance, you can “cheat” by changing the sequence you have in mind, so long as it does not contradict the information you have revealed so far. It turns out that under these conditions, you can always force the adversary to get 33 333 misses before they can guess every number in your sequence. Your job is to write a program that does so.

# Interaction

This is an interactive problem.

Your program should begin by printing $k$ $2 \leq k \leq 1 0 0 0 0 1$ ), the length of your sequence, as a single integer on a single line. After this, you will receive one integer $x$ on a single line. This integer is guaranteed to be between $- 1$ and 100 000 inclusive.

• If $x = - 1$ , the adversary has given up; your program should print all $k$ integers in your sequence in order, one line per integer, and then exit. The adversary is guaranteed to give this input after it has gotten 33 333 misses, though it may do so earlier. After printing all $k$ integers, your program should exit. If you print a valid sequence consistent with your previous responses, your submission will be considered correct for this test case.

• If $x$ is not in your sequence, print $- 1$ on a single line.

• If $x$ is in your sequence, print a single integer $i$ on a single line, such that $x$ is the ith (1-indexed) number in the sequence. If you have printed every integer from 1 to $k$ , your program should now exit, and your submission will receive a Wrong Answer verdict.

Do not forget to flush the output after every integer you print.

After this, if your program has not yet exited, the process will repeat, with you receiving another single integer.
he adversary is guaranteed to never repeat integers.

The adversary may employ different guessing strategies on different runs.

Read	Sample Interaction 1

50001	Write

0

	1

1

	-1

-1

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

using namespace std;

static long long queries = 0;
static long long query_limit = 0;
static const int MISS_LIMIT = 33333;
static bool metrics_logged = false;

static void log_metrics() {
    if (metrics_logged) return;
    metrics_logged = true;
    try {

        if (query_limit == 0) query_limit = 100005;
        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 read_int(int &val) {
    if (!(cin >> val)) return false;
    return true;
}

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

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

    int n_guesses = inf.readInt();
    vector<int> guesses;
    guesses.reserve(n_guesses);
    for (int i = 0; i < n_guesses; i++) {
        guesses.push_back(inf.readInt());
    }

    query_limit = n_guesses + 5;

    int k;
    if (!read_int(k)) {
        finish(_pe, "Failed to read k (sequence length)");
    }

    if (k < 2 || k > 100001) {
        finish(_wa, format("k is out of bounds: %d", k));
    }

    vector<int> history(100001, -2);

    vector<bool> index_revealed(k + 1, false);

    int revealed_count = 0;
    int misses = 0;

    for (int x : guesses) {

        if (misses >= MISS_LIMIT) {
            break;
        }

        if (revealed_count == k) {
            finish(_wa, "Contestant revealed all numbers before adversary gave up");
        }

        cout << x << endl;
        queries++;

        int resp;
        if (!read_int(resp)) {
            finish(_pe, format("Failed to read response for guess %d", x));
        }

        if (resp == -1) {

            misses++;

            if (history[x] != -2 && history[x] != -1) {
                 finish(_wa, format("Inconsistency: value %d now claimed miss, previously claimed at index %d", x, history[x]));
            }
            history[x] = -1;
        } else {

            if (resp < 1 || resp > k) {
                finish(_wa, format("Response index %d out of bounds [1, %d]", resp, k));
            }

            if (history[x] != -2 && history[x] != resp) {
                if (history[x] == -1)
                    finish(_wa, format("Inconsistency: value %d claimed at %d, but previously missed", x, resp));
                else
                    finish(_wa, format("Inconsistency: value %d claimed at %d, but previously at %d", x, resp, history[x]));
            }

            if (history[x] == -2) {
                if (index_revealed[resp]) {
                    finish(_wa, format("Index %d claimed for value %d, but already used by another value", resp, x));
                }
                history[x] = resp;
                index_revealed[resp] = true;
                revealed_count++;
            }
        }
    }

    cout << -1 << endl;
    queries++;

    vector<int> seq;
    seq.reserve(k);
    for (int i = 0; i < k; i++) {
        int val;
        if (!read_int(val)) {
             finish(_pe, format("Failed to read sequence element %d of %d", i+1, k));
        }
        seq.push_back(val);
    }

    if (seq.empty()) finish(_wa, "Sequence is empty");

    if (seq[0] != 0) {
        finish(_wa, format("Sequence must start with 0, found %d", seq[0]));
    }
    if (seq.back() != 100000) {
        finish(_wa, format("Sequence must end with 100000, found %d", seq.back()));
    }

    vector<bool> in_seq(100001, false);
    in_seq[seq[0]] = true;

    for (int i = 1; i < k; i++) {
        int diff = seq[i] - seq[i-1];
        if (diff != 1 && diff != 2) {
            finish(_wa, format("Invalid step at index %d: %d -> %d (diff %d). Must be 1 or 2.", i+1, seq[i-1], seq[i], diff));
        }
        if (seq[i] < 0 || seq[i] > 100000) {
            finish(_wa, format("Sequence value out of bounds: %d", seq[i]));
        }
        in_seq[seq[i]] = true;
    }

    for (int v = 0; v <= 100000; v++) {

        if (history[v] == -2) continue;

        if (history[v] == -1) {

            if (in_seq[v]) {
                finish(_wa, format("Contestant said %d was a miss, but it appears in the final sequence", v));
            }
        } else {

            int idx = history[v] - 1;
            if (idx >= k) {
                finish(_wa, "Internal error: index out of bounds");
            }
            if (seq[idx] != v) {
                finish(_wa, format("Contestant said %d was at index %d, but sequence has %d at that position", v, history[v], seq[idx]));
            }
        }
    }

    finish(_ok, format("Correct. Misses forced: %d", misses));
    return 0;
}

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

using namespace std;

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

static void log_metrics() {
    try {
        if (tout.is_open()) {
            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 first_token = inf.readInt();
    vector<int> p;
    int max_val = 100000;

    if (first_token > 100) {

        int count = first_token;
        p.reserve(count);
        for(int i = 0; i < count; i++) {
            p.push_back(inf.readInt());
        }
    } else {

        int strategy = first_token;
        long long seed = inf.readLong();

        p.resize(max_val + 1);
        iota(p.begin(), p.end(), 0);

        mt19937_64 rng(seed);

        if (strategy == 0) {

            shuffle(p.begin(), p.end(), rng);
        } else if (strategy == 1) {

        } else if (strategy == 2) {

            reverse(p.begin(), p.end());
        } else if (strategy == 3) {

            vector<int> tmp;
            tmp.reserve(p.size());
            int l = 0, r = p.size() - 1;
            while(l <= r) {
                if (l == r) tmp.push_back(p[l++]);
                else {
                    tmp.push_back(p[l++]);
                    tmp.push_back(p[r--]);
                }
            }
            p = tmp;
        } else if (strategy == 4) {

            sort(p.begin(), p.end(), [](int a, int b){
                return abs(a - 50000) < abs(b - 50000);
            });
        } else {

            shuffle(p.begin(), p.end(), rng);
        }
    }

    query_limit = p.size();
    log_metrics();

    int k;
    if (!(cin >> k)) {
        finish(_wa, "Failed to read k from contestant");
    }

    if (k < 50001 || k > 100001) {
        finish(_wa, "Invalid k: " + to_string(k) + " (must be between 50001 and 100001)");
    }

    int misses = 0;
    int found_cnt = 0;
    int p_idx = 0;

    vector<int> known_seq(k + 1, -2);

    vector<bool> is_miss(max_val + 1, false);

    while (misses < 33333) {

        if (found_cnt == k) {
            finish(_wa, "Contestant revealed all numbers before forcing 33333 misses");
        }

        if (p_idx >= (int)p.size()) {

            finish(_wa, "Exhausted all guesses without finding sequence (inconsistent state)");
        }

        int guess = p[p_idx++];

        cout << guess << endl;
        queries++;
        if (queries % 1000 == 0) log_metrics();

        if (queries > 200000) {
            finish(_pe, "Too many queries");
        }

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

        if (resp == -1) {
            misses++;
            is_miss[guess] = true;
        } else {

            if (resp < 1 || resp > k) {
                finish(_wa, "Response index out of range: " + to_string(resp));
            }

            if (known_seq[resp] != -2) {

                if (known_seq[resp] != guess) {
                    finish(_wa, "Inconsistent response: index " + to_string(resp) + " reported for " + to_string(guess) + " but previously " + to_string(known_seq[resp]));
                }
            } else {
                known_seq[resp] = guess;
                found_cnt++;
            }
        }
    }

    cout << -1 << endl;

    vector<int> final_seq;
    final_seq.reserve(k);
    for(int i = 0; i < k; i++) {
        int val;
        if (!(cin >> val)) {
            finish(_wa, "Failed to read final sequence");
        }
        final_seq.push_back(val);
    }

    if (final_seq[0] != 0) {
        finish(_wa, "Sequence must start with 0");
    }
    if (final_seq.back() != 100000) {
        finish(_wa, "Sequence must end with 100000");
    }
    if ((int)final_seq.size() != k) {
        finish(_wa, "Sequence length mismatch");
    }

    for(size_t i = 1; i < final_seq.size(); i++) {
        long long diff = (long long)final_seq[i] - final_seq[i-1];
        if (diff != 1 && diff != 2) {
            finish(_wa, "Invalid step size " + to_string(diff) + " at index " + to_string(i+1));
        }
    }

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

        if (known_seq[i] != -2) {
            if (final_seq[i-1] != known_seq[i]) {
                finish(_wa, "Final sequence mismatch at index " + to_string(i) + ": expected " + to_string(known_seq[i]) + ", got " + to_string(final_seq[i-1]));
            }
        }
    }

    for(int x : final_seq) {
        if (x >= 0 && x <= max_val) {
            if (is_miss[x]) {
                finish(_wa, "Value " + to_string(x) + " is in final sequence but was reported as MISS");
            }
        }
    }

    finish(_ok, "Correct");
    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 min_val = 0;
    int max_val = 100000;
    int count = max_val - min_val + 1;

    if (mode == "non") {

        vector<int> p(count);
        iota(p.begin(), p.end(), min_val);

        long long seed_val = 0;

        if (argc > 1) seed_val = atoll(argv[1]);

        if (seed_val == 1) {

        } else if (seed_val == 2) {

            reverse(p.begin(), p.end());
        } else if (seed_val == 3) {

            vector<int> temp;
            temp.reserve(count);
            int l = 0, r = count - 1;
            while (l <= r) {
                if (l == r) {
                    temp.push_back(p[l]);
                    l++;
                } else {
                    temp.push_back(p[l++]);
                    temp.push_back(p[r--]);
                }
            }
            p = temp;
        } else {

            shuffle(p.begin(), p.end());
        }

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

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

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

        int strategy = 0;

        if (seed_val == 1) strategy = 1;
        else if (seed_val == 2) strategy = 2;
        else if (seed_val == 3) strategy = 3;
        else {

            strategy = rnd.next(0, 5);
        }

        int sub_seed = rnd.next(1, 1000000000);

        cout << strategy << " " << sub_seed << endl;

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

    return 0;
}


This is an interactive problem.

You are given a tree consisting of $n$ nodes numbered with integers from $1$ to $n$. Ayush and Ashish chose two secret distinct nodes in the tree. You need to find out both the nodes. You can make the following query:

* Provide a list of nodes and you will receive a node from that list whose sum of distances to both the hidden nodes is minimal (if there are multiple such nodes in the list, you will receive any one of them). You will also get the sum of distances of that node to the hidden nodes.

Recall that a tree is a connected graph without cycles. The distance between two nodes is defined as the number of edges in the simple path between them.

More formally, let's define two hidden nodes as $s$ and $f$. In one query you can provide the set of nodes $\{a_1, a_2, \ldots, a_c\}$ of the tree. As a result, you will get two numbers $a_i$ and $dist(a_i, s) + dist(a_i, f)$. The node $a_i$ is any node from the provided set, for which the number $dist(a_i, s) + dist(a_i, f)$ is minimal.

You can ask no more than $11$ queries.

Input

The first line contains a single integer $t$ $(1 \leq t \leq 10)$ — the number of test cases. Please note, how the interaction process is organized.

The first line of each test case consists of a single integer $n$ $(2 \le n \le 1000)$ — the number of nodes in the tree.

The next $n - 1$ lines consist of two integers $u$, $v$ $(1 \le u, v \le n, u \ne v)$ — the edges of the tree.

Interaction

To ask a query print a single line:

* In the beginning print "? c " (without quotes) where $c$ $(1 \leq c \leq n)$ denotes the number of nodes being queried, followed by $c$ distinct integers in the range $[1, n]$  — the indices of nodes from the list.

For each query, you will receive two integers $x$, $d$ — the node (among the queried nodes) with the minimum sum of distances to the hidden nodes and the sum of distances from that node to the hidden nodes. If the subset of nodes queried is invalid or you exceeded the number of queries then you will get $x = d = -1$. In this case, you should terminate the program immediately.

When you have guessed the hidden nodes, print a single line "! " (without quotes), followed by two integers in the range $[1, n]$  — the hidden nodes. You can output the hidden nodes in any order.

After this, you should read a string. If you guess the nodes correctly, you will receive the string "Correct". In this case, you should continue solving the remaining test cases or terminate the program, if all test cases were solved. Otherwise, you will receive the string "Incorrect". In this case, you should terminate the program immediately.

Guessing the hidden nodes does not count towards the number of queries asked.

The interactor is not adaptive. The hidden nodes do not change with queries.

Do not forget to read the string "Correct" / "Incorrect" after guessing the hidden nodes.

You need to solve each test case before receiving the input for the next test case.

The limit of $11$ queries applies to each test case and not to the entire input.

After printing 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;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see the documentation for other languages.

Example

Input

```
1
3
1 2
1 3

1 1

2 3

3 1

3 1

Correct
```

Output

```
? 1 1

? 1 2

? 1 3

? 2 2 3

! 1 3
```

Note

The tree from the first test is shown below, and the hidden nodes are $1$ and $3$.

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

#include "testlib.h"
#include <algorithm>
#include <csignal>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

static int queries = 0;
static long long query_limit = -1;

void log_queries() {
    tout << "queries=" << queries << "\n";
    tout << "query_limit=" << query_limit << "\n";
}

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

static vector<int> bfs_dist(const vector<vector<int>>& g, int src) {
    const int n = int(g.size()) - 1;
    vector<int> dist(n + 1, -1);
    queue<int> q;
    dist[src] = 0;
    q.push(src);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : g[u]) {
            if (dist[v] != -1) {
                continue;
            }
            dist[v] = dist[u] + 1;
            q.push(v);
        }
    }
    return dist;
}

int main(int argc, char* argv[]) {
    registerInteraction(argc, argv);
    signal(SIGPIPE, SIG_IGN);
    atexit(log_queries);

    const int t = inf.readInt();
    cout << t << "\n" << flush;

    const long long per_case_limit = 11;
    query_limit = per_case_limit * (long long)t;

    log_queries();

    for (int tc = 0; tc < t; tc++) {
        const int n = inf.readInt();
        vector<pair<int, int>> edges;
        edges.reserve(n - 1);
        vector<vector<int>> g(n + 1);
        for (int i = 0; i < n - 1; i++) {
            int u = inf.readInt();
            int v = inf.readInt();
            edges.push_back({u, v});
            g[u].push_back(v);
            g[v].push_back(u);
        }
        const int s = inf.readInt();
        const int f = inf.readInt();
        if (s == f) {
            quit_with(_fail, "Invalid hidden nodes");
        }

        vector<int> dist_s = bfs_dist(g, s);
        vector<int> dist_f = bfs_dist(g, f);

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

        int used = 0;
        while (true) {
            string cmd;
            if (!(cin >> cmd)) {
                quit_with(_pe, "Unexpected EOF");
            }

            if (cmd == "?") {
                used++;
                queries++;
                if (used > per_case_limit) {
                    cout << "-1 -1\n" << flush;
                    quit_with(_pe, "Too many queries");
                }

                int c;
                if (!(cin >> c)) {
                    cout << "-1 -1\n" << flush;
                    quit_with(_pe, "Invalid query");
                }
                if (c < 1 || c > n) {
                    cout << "-1 -1\n" << flush;
                    quit_with(_pe, "Invalid c");
                }

                vector<int> nodes(c);
                vector<char> seen(n + 1, 0);
                for (int i = 0; i < c; i++) {
                    if (!(cin >> nodes[i])) {
                        cout << "-1 -1\n" << flush;
                        quit_with(_pe, "Invalid node list");
                    }
                    int v = nodes[i];
                    if (v < 1 || v > n || seen[v]) {
                        cout << "-1 -1\n" << flush;
                        quit_with(_pe, "Invalid node list");
                    }
                    seen[v] = 1;
                }

                int best = nodes[0];
                int best_d = dist_s[best] + dist_f[best];
                for (int v : nodes) {
                    int d = dist_s[v] + dist_f[v];
                    if (d < best_d || (d == best_d && v < best)) {
                        best = v;
                        best_d = d;
                    }
                }
                cout << best << " " << best_d << "\n" << flush;
                continue;
            }

            if (cmd == "!") {
                int a, b;
                if (!(cin >> a >> b)) {
                    quit_with(_pe, "Invalid answer format");
                }
                bool ok = (a == s && b == f) || (a == f && b == s);
                cout << (ok ? "Correct" : "Incorrect") << "\n" << flush;
                if (!ok) {
                    quit_with(_wa, "Wrong answer");
                }
                break;
            }

            quit_with(_pe, "Unknown command: " + cmd);
        }
    }

    quit_with(_ok, "All tests correct");
}

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

static vector<pair<int, int>> gen_random_tree(int n) {
    vector<pair<int, int>> edges;
    edges.reserve(n - 1);
    for (int i = 2; i <= n; i++) {
        int p = rnd.next(1, i - 1);
        edges.push_back({p, i});
    }
    return edges;
}

static vector<pair<int, int>> gen_path(int n) {
    vector<pair<int, int>> edges;
    edges.reserve(n - 1);
    for (int i = 1; i + 1 <= n; i++) edges.push_back({i, i + 1});
    return edges;
}

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

static pair<int, int> diameter_endpoints(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);
    }

    auto bfs_far = [&](int src) -> pair<int, vector<int>> {
        vector<int> dist(n + 1, -1);
        queue<int> q;
        dist[src] = 0;
        q.push(src);
        int far = src;
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            if (dist[u] > dist[far]) far = u;
            for (int v : g[u]) {
                if (dist[v] != -1) continue;
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
        return {far, dist};
    };

    int a = bfs_far(1).first;
    int b = bfs_far(a).first;
    if (a == b) {
        b = (a % n) + 1;
    }
    return {a, b};
}

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

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

    int t = 3;
    if (seed == 1) t = 1;
    else if (seed == 2) t = 2;
    else if (seed <= 10) t = 3;
    else t = 5;
    t = max(1, min(10, t));

    cout << t << "\n";
    for (int tc = 0; tc < t; tc++) {
        int n = 1000;
        if (seed == 1) n = 2;
        else if (seed == 2) n = 3;
        else if (seed <= 10) n = 50 + (int)seed * 20;
        n = max(2, min(1000, n));

        vector<pair<int, int>> edges;
        int kind = (int)((seed + tc) % 3);
        if (kind == 0) edges = gen_path(n);
        else if (kind == 1) edges = gen_balanced(n);
        else edges = gen_random_tree(n);

        auto [s, f] = diameter_endpoints(n, edges);

        cout << n << "\n";
        for (auto [u, v] : edges) cout << u << " " << v << "\n";
        cout << s << "\n" << f << "\n";
    }
    return 0;
}


# This is an interactive problem.

In the simplified version of the game “Understand,” you find yourself in a $2 5 6 \times 2 5 6$ grid. There are $n$ items within this grid whose precise positions are yet unknown. It is possible that multiple items are in the same grid cell.

Your task is to determine the locations of each item through a series of interactive queries, with a limit of no more than 16 queries. Each query allows you to draw a simple path on the grid, and the interactor will respond with a binary string of length $n$ , representing whether each item is on that path.

It is guaranteed that the interactor is non-adaptive, meaning the positions of the items are already determined before you start querying.

# Input

The first line of input contains an integer $n$ ( $1 \leq n \leq 1 0 0 0 0$ ), denoting the number of items in the grid.

# Interaction Protocol

The interaction begins after reading the integer $n$ .

Then, make at most 16 queries. To make a query: output “? $x _ { 0 } \ y _ { 0 } \ k \ s ^ { \prime }$ in a line. Here, $1 \leq x _ { 0 } , y _ { 0 } \leq 2 5 6$ represents that the path starts at the $x _ { 0 }$ -th row from top to bottom and the $y _ { 0 }$ -th column from left to right. $1 \leq k \leq 2 5 6 \times 2 5 6$ represents the length of the simple path. $s$ is a string of length $k - 1$ consisting of characters ‘L,’ ‘R,’‘ U’, and ‘D.’ The $i$ -th character represents the direction of movement from the $i$ -th cell to the $( i + 1 )$ -th cell along the path, where

• ‘L’ means moving from $( x , y )$ to $( x , y - 1 )$ , • ‘R’ means moving from $( x , y )$ to $( x , y + 1 )$ , • ‘U’ means moving from $( x , y )$ to $( x - 1 , y )$ , • ‘D’ means moving from $( x , y )$ to $( x + 1 , y )$ .

If $k = 1$ , you can simply output “? $x _ { 0 } \ y _ { 0 } \ k ^ { \prime }$ and may not output the additional blank space (It would be OK doing so, though).

Here, the path you output must be simple, meaning your path should not pass the same grid more than once. Also, the path must lie in the $2 5 6 \times 2 5 6$ grid, meaning each grid $( x , y )$ in the path must satisfy $1 \leq x , y \leq 2 5 6$ .

After you output the query in the correct format, read in a binary string $t$ of length $n$ , where the $i$ -th $1 \leq i \leq n$ ) character of $t$ is $^ 1$ if the $i$ -th item is on your path, and the $i$ -th $\ b { 1 } \leq \ b { i } \leq \ b { n }$ ) character of $t$ is 0 otherwise. If your query is invalid or you have made more than 16 queries, you will receive a single character ‘ $\_ ^ { 7 }$ instead. Upon reading it, your program must terminate immediately to receive a “Wrong Answer” verdict, or you could get any possible verdict.

At any point of the interaction, if you want to guess the locations of each item, output “ ! $x _ { 1 } ~ y _ { 1 } ~ x _ { 2 } ~ y _ { 2 } \cdot \cdot \cdot { x _ { n } }$ $y _ { n } ^ { \dag }$ in a line, where $( x _ { i } , y _ { i } )$ represents the location of the $i$ -th item in your guess. This guess does not count as a query. After doing that, you should terminate your program immediately.

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

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

# Example

standard input	standard output

4	？ 31 9 RRRUULLD

0101

1111	？214 RRR

1100	？ 2 1 6 URDDR

	？241

0001	!21222324

# Note

Note that additional empty lines in the sample test are for better understanding, and you should not output any additional empty lines in your program.

Here, we provide graphical illustrations of the interaction in the sample test. In the picture below, we only show the upper-left $4 \times 4$ part of the board, but the actual size of the board is $2 5 6 \times 2 5 6$ . The locations of all four items are labeled with stars. The starting point of each query path is labeled with a square, and the result is shown below the path (filled circles represent 1, and unfilled circles represent $0$ ).

![](images/985d53d6ed28714786240457fb9e5635f5f0c80853739330fd8925c3bd5fda40.jpg)

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

static long long queries = 0;
static const long long query_limit = 16;
static bool finished = false;

static int visited_grid[257][257];

struct Point {
    int r, c;
    bool operator==(const Point& other) const {
        return r == other.r && c == other.c;
    }
};

static void log_metrics() {

    if (!finished) {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    }
}

static void finish(TResult verdict, const string& msg) {

    tout << "queries=" << queries << endl;
    tout << "query_limit=" << query_limit << endl;
    finished = true;
    quitf(verdict, "%s", msg.c_str());
}

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

    int n = inf.readInt(1, 10000, "n");
    vector<Point> items(n);
    for (int i = 0; i < n; i++) {
        items[i].r = inf.readInt(1, 256, "r_i");
        items[i].c = inf.readInt(1, 256, "c_i");
    }

    cout << n << endl;

    int hard_cap = 2000;

    while (true) {

        log_metrics();

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

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

            break;
        }

        if (token == "!") {

            vector<Point> guess(n);
            for (int i = 0; i < n; i++) {
                if (!(cin >> guess[i].r >> guess[i].c)) {
                    finish(_wa, "Failed to read final answer coordinates");
                }
            }

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

            if (ok) {
                finish(_ok, "Correct guess");
            } else {
                finish(_wa, "Incorrect items");
            }
        }

        int x0, y0, k;
        if (token == "?") {
            if (!(cin >> x0 >> y0 >> k)) finish(_wa, "Invalid query format");
        } else {

            try {
                x0 = stoi(token);
            } catch (...) {
                finish(_wa, "Invalid token (expected integer, ?, or !)");
            }
            if (!(cin >> y0 >> k)) finish(_wa, "Invalid query format");
        }

        if (x0 < 1 || x0 > 256 || y0 < 1 || y0 > 256) {
            cout << "_" << endl;
            finish(_wa, "Starting coordinates out of bounds");
        }
        if (k < 1 || k > 65536) {
            cout << "_" << endl;
            finish(_wa, "Path length k out of valid range");
        }

        string s = "";
        if (k > 1) {
            if (!(cin >> s)) finish(_wa, "Failed to read path string");
        }

        if (queries >= query_limit) {
            cout << "_" << endl;
            finish(_wa, "Query limit exceeded");
        }

        if ((int)s.length() != k - 1) {
            cout << "_" << endl;
            finish(_wa, "String length mismatch with k");
        }

        vector<Point> path;
        path.reserve(k);
        path.push_back({x0, y0});

        int curr_r = x0;
        int curr_c = y0;
        bool invalid_move = false;

        for (char c : s) {
            if (c == 'L') curr_c--;
            else if (c == 'R') curr_c++;
            else if (c == 'U') curr_r--;
            else if (c == 'D') curr_r++;
            else { invalid_move = true; break; }

            if (curr_r < 1 || curr_r > 256 || curr_c < 1 || curr_c > 256) {
                invalid_move = true;
                break;
            }
            path.push_back({curr_r, curr_c});
        }

        if (invalid_move) {
            cout << "_" << endl;
            finish(_wa, "Invalid move or path out of bounds");
        }

        vector<Point> sorted_path = path;
        sort(sorted_path.begin(), sorted_path.end(), [](const Point& a, const Point& b) {
            return a.r != b.r ? a.r < b.r : a.c < b.c;
        });

        bool simple = true;
        for (size_t i = 1; i < sorted_path.size(); i++) {
            if (sorted_path[i] == sorted_path[i-1]) {
                simple = false;
                break;
            }
        }

        if (!simple) {
            cout << "_" << endl;
            finish(_wa, "Path is not simple (visited same cell twice)");
        }

        int q_id = (int)queries + 1;
        for (const auto& p : path) {
            visited_grid[p.r][p.c] = q_id;
        }

        string resp = "";
        resp.reserve(n);
        for (int i = 0; i < n; i++) {
            if (visited_grid[items[i].r][items[i].c] == q_id) {
                resp += '1';
            } else {
                resp += '0';
            }
        }

        cout << resp << endl;
        queries++;
    }

    finish(_wa, "Unexpected termination");
}

#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);

    string seed_str = (argc > 1 ? argv[1] : "");

    if (n == -1) {
        if (seed_str == "1") n = 4;
        else if (seed_str == "2") n = 1;
        else if (seed_str == "3") n = 10000;
        else if (seed_str == "4") n = 10000;
        else if (seed_str == "5") n = 10000;
        else n = rnd.next(1, 10000);
    }

    n = max(1, min(n, 10000));

    int ROWS = 256;
    int COLS = 256;
    vector<pair<int, int>> points(n);

    int strategy = -1;

    if (seed_str == "1") {
        strategy = 0;
    } else if (seed_str == "2") {
        points[0] = {1, 1};
        strategy = -1;
    } else if (seed_str == "3") {

        for(auto& p : points) p = {ROWS, COLS};
        strategy = -1;
    } else if (seed_str == "4") {
        strategy = 1;
    } else if (seed_str == "5") {
        strategy = 3;
    } else if (seed_str == "6") {
        strategy = 2;
    } else if (seed_str == "7") {
        strategy = 4;
    } else {

        int r = rnd.next(100);
        if (r < 50) strategy = 0;
        else if (r < 70) strategy = 2;
        else if (r < 85) strategy = 1;
        else if (r < 95) strategy = 4;
        else strategy = 3;
    }

    if (strategy == 0) {
        for(int i = 0; i < n; i++) {
            points[i] = {rnd.next(1, ROWS), rnd.next(1, COLS)};
        }
    } else if (strategy == 1) {
        set<pair<int,int>> distinct_pts;

        while((int)distinct_pts.size() < n) {
            distinct_pts.insert({rnd.next(1, ROWS), rnd.next(1, COLS)});
        }
        vector<pair<int,int>> v(distinct_pts.begin(), distinct_pts.end());
        shuffle(v.begin(), v.end());
        points = v;
    } else if (strategy == 2) {
        int num_centers = rnd.next(1, 5);
        vector<pair<int,int>> centers(num_centers);
        for(int i = 0; i < num_centers; i++)
            centers[i] = {rnd.next(1, ROWS), rnd.next(1, COLS)};

        for(int i = 0; i < n; i++) {
            int c_idx = rnd.next(num_centers);
            int r = centers[c_idx].first + rnd.next(-15, 15);
            int c = centers[c_idx].second + rnd.next(-15, 15);
            points[i] = {max(1, min(ROWS, r)), max(1, min(COLS, c))};
        }
    } else if (strategy == 3) {
        for(int i = 0; i < n; i++) {
            int v = rnd.next(1, min(ROWS, COLS));
            points[i] = {v, v};
        }
    } else if (strategy == 4) {
        int fixed_axis = rnd.next(2);
        int fixed_val = rnd.next(1, 256);
        for(int i = 0; i < n; i++) {
            if (fixed_axis == 0) points[i] = {fixed_val, rnd.next(1, COLS)};
            else points[i] = {rnd.next(1, ROWS), fixed_val};
        }
    }

    if (mode == "non") {
        cout << n << endl;
        for (int i = 0; i < n; i++) {
            cout << points[i].first << " " << points[i].second << "\n";
        }
    } else if (mode == "adp") {

        cout << n << endl;
        for (int i = 0; i < n; i++) {
            cout << points[i].first << " " << points[i].second << "\n";
        }
    }

    return 0;
}