This is an interactive problem!

Nastia has a hidden permutation $p$ of length $n$ consisting of integers from $1$ to $n$. You, for some reason, want to figure out the permutation. To do that, you can give her an integer $t$ ($1 \le t \le 2$), two different indices $i$ and $j$ ($1 \le i, j \le n$, $i \neq j$), and an integer $x$ ($1 \le x \le n - 1$).

Depending on $t$, she will answer:

* $t = 1$: $\max{(\min{(x, p_i)}, \min{(x + 1, p_j)})}$;
* $t = 2$: $\min{(\max{(x, p_i)}, \max{(x + 1, p_j)})}$.

You can ask Nastia at most $\lfloor \frac {3 \cdot n} { 2} \rfloor + 30$ times. It is guaranteed that she will not change her permutation depending on your queries. Can you guess the permutation?

Input

The input consists of several test cases. In the beginning, you receive the integer $T$ ($1 \le T \le 10\,000$) — the number of test cases.

At the beginning of each test case, you receive an integer $n$ ($3 \le n \le 10^4$) — the length of the permutation $p$.

It's guaranteed that the permutation is fixed beforehand and that the sum of $n$ in one test doesn't exceed $2 \cdot 10^4$.

Interaction

To ask a question, print "? $t$ $i$ $j$ $x$" ($t = 1$ or $t = 2$, $1 \le i, j \le n$, $i \neq j$, $1 \le x \le n - 1$) Then, you should read the answer.

If we answer with $−1$ instead of a valid answer, that means you exceeded the number of queries or made an invalid query. Exit immediately after receiving $−1$ and you will see the Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

To print the answer, print "! $p_1$ $p_2$ $\ldots$ $p_{n}$ (without quotes). Note that answering doesn't count as one of the $\lfloor \frac {3 \cdot n} {2} \rfloor + 30$ queries.

After printing a query or printing the answer, 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 the documentation for other languages.

Example

Input

```
2
4

3

2

5

3
```

Output

```
? 2 4 1 3

? 1 2 4 2

! 3 1 4 2

? 2 3 4 2

! 2 5 3 4 1
```

Note

Consider the first test case.

The hidden permutation is $[3, 1, 4, 2]$.

We print: "? $2$ $4$ $1$ $3$" and get back $\min{(\max{(3, p_4}), \max{(4, p_1)})} = 3$.

We print: "? $1$ $2$ $4$ $2$" and get back $\max{(\min{(2, p_2)}, \min{(3, p_4)})} = 2$.

Consider the second test case.

The hidden permutation is $[2, 5, 3, 4, 1]$.

We print: "? $2$ $3$ $4$ $2$" and get back $\min{(\max{(2, p_3}), \max{(3, p_4)})} = 3$.

#include "testlib.h"

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

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

struct HiddenTest {
    int n = 0;
    vector<int> p;
};

static int compute_answer(int t, int x, int pi, int pj) {

    if (t == 1) {
        return max(min(x, pi), min(x + 1, pj));
    }
    if (t == 2) {
        return min(max(x, pi), max(x + 1, pj));
    }
    return -1;
}

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

    int T = inf.readInt();
    if (T < 1) {
        die(_fail, "Invalid hidden input: T < 1");
    }

    vector<HiddenTest> tests;
    tests.reserve(T);

    query_limit = 0;
    for (int tc = 0; tc < T; tc++) {
        int n = inf.readInt();
        if (n < 3) {
            die(_fail, "Invalid hidden input: n < 3");
        }
        vector<int> p;
        p.reserve(n);
        for (int i = 0; i < n; i++) {
            p.push_back(inf.readInt());
        }
        tests.push_back(HiddenTest{n, move(p)});
        query_limit += (3LL * n) / 2 + 30;
    }

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

    cout << T << endl;
    cout.flush();

    for (int tc = 0; tc < T; tc++) {
        const int n = tests[tc].n;
        const vector<int>& p = tests[tc].p;

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

        while (true) {
            string cmd;
            if (!(cin >> cmd)) {
                die(_wa, "Unexpected EOF from solution");
            }

            if (cmd == "?") {
                if (queries >= query_limit) {
                    cout << -1 << endl;
                    cout.flush();
                    die(_wa, "Query limit exceeded");
                }
                if (queries >= hard_cap) {
                    die(_pe, "Too many queries (hard cap)");
                }

                int t, i, j, x;
                if (!(cin >> t >> i >> j >> x)) {
                    cout << -1 << endl;
                    cout.flush();
                    die(_wa, "Invalid query format");
                }
                if (!(t == 1 || t == 2)) {
                    cout << -1 << endl;
                    cout.flush();
                    die(_wa, "Invalid t (must be 1 or 2)");
                }
                if (i < 1 || i > n || j < 1 || j > n || i == j) {
                    cout << -1 << endl;
                    cout.flush();
                    die(_wa, "Invalid i/j");
                }
                if (x < 1 || x > n - 1) {
                    cout << -1 << endl;
                    cout.flush();
                    die(_wa, "Invalid x");
                }

                queries++;
                log_metrics();

                const int pi = p[i - 1];
                const int pj = p[j - 1];
                const int ans = compute_answer(t, x, pi, pj);
                cout << ans << endl;
                cout.flush();
                continue;
            }

            if (cmd == "!") {
                vector<int> guess;
                guess.reserve(n);
                for (int i = 0; i < n; i++) {
                    int v;
                    if (!(cin >> v)) {
                        die(_wa, "Unexpected EOF in answer");
                    }
                    guess.push_back(v);
                }
                if (guess != p) {
                    die(_wa, "Wrong answer");
                }
                break;
            }

            die(_pe, "Unknown command (expected '?' or '!')");
        }
    }

    die(_ok, "OK");
}

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

    const int MAX_SUM_N = 20000;
    const int MAX_N_PER_TEST = 10000;
    const int MIN_N = 3;

    struct TestCase {
        int n;
        vector<int> p;
    };
    vector<TestCase> tests;
    int remaining_sum = MAX_SUM_N;

    long long seed_val = -1;
    try {
        string s = argv[1];
        bool is_num = true;
        for (char c : s) if (!isdigit(c)) is_num = false;
        if (is_num && !s.empty()) seed_val = stoll(s);
    } catch (...) {}

    auto gen_perm = [&](int n, string type) {
        vector<int> p(n);
        iota(p.begin(), p.end(), 1);
        if (type == "random") {
            shuffle(p.begin(), p.end());
        } else if (type == "rev") {
            reverse(p.begin(), p.end());
        } else if (type == "shift") {
            int k = rnd.next(1, n - 1);
            rotate(p.begin(), p.begin() + k, p.end());
        } else if (type == "swap") {

            int k = rnd.next(1, max(1, (int)sqrt(n)));
            for(int i = 0; i < k; ++i) {
                int a = rnd.next(0, n - 1);
                int b = rnd.next(0, n - 1);
                swap(p[a], p[b]);
            }
        } else if (type == "interleave") {

            vector<int> q(n);
            int l = 1, r = n;
            for(int i = 0; i < n; ++i) {
                if (i % 2 == 0) q[i] = l++;
                else q[i] = r--;
            }
            p = q;
        }
        return p;
    };

    if (seed_val == 1) {

        int n = MAX_N_PER_TEST;
        tests.push_back({n, gen_perm(n, "random")});
    } else if (seed_val == 2) {

        int n = MAX_N_PER_TEST;
        tests.push_back({n, gen_perm(n, "rev")});
    } else if (seed_val == 3) {

        int n = MIN_N;
        tests.push_back({n, gen_perm(n, "random")});
    } else {

        int strat = rnd.next(0, 10);

        if (strat < 4) {

            while (remaining_sum >= MIN_N) {
                int max_can = min(remaining_sum, MAX_N_PER_TEST);

                int n = rnd.next(max(MIN_N, max_can / 2), max_can);
                tests.push_back({n, gen_perm(n, "random")});
                remaining_sum -= n;

                if (tests.size() >= 5 && rnd.next(3) == 0) break;
            }
        } else if (strat < 7) {

            while (remaining_sum >= MIN_N) {
                int n = rnd.next(MIN_N, min(remaining_sum, 60));
                tests.push_back({n, gen_perm(n, "random")});
                remaining_sum -= n;
                if (tests.size() >= 1000) break;
            }
        } else {

            while (remaining_sum >= MIN_N) {
                int max_can = min(remaining_sum, MAX_N_PER_TEST);
                int n;
                int p = rnd.next(100);

                if (p < 20) n = rnd.next(MIN_N, 50);
                else if (p < 50) n = rnd.next(50, 500);
                else n = rnd.next(500, max(500, max_can));

                n = max(MIN_N, min(n, max_can));

                string type = "random";
                int t = rnd.next(10);
                if (t == 0) type = "rev";
                else if (t == 1) type = "interleave";
                else if (t == 2) type = "shift";
                else if (t == 3) type = "swap";

                tests.push_back({n, gen_perm(n, type)});
                remaining_sum -= n;

                if (tests.size() >= 500) break;
            }
        }
    }

    if (tests.empty()) {
        int n = rnd.next(MIN_N, min(MAX_SUM_N, MAX_N_PER_TEST));
        tests.push_back({n, gen_perm(n, "random")});
    }

    println(tests.size());
    for (const auto& t : tests) {
        println(t.n);
        println(t.p);
    }

    return 0;
}


This is an interactive problem.

A thin black disk is laid flat on the square bottom of a white box. The sides of the box bottom are $1 0 ^ { 5 }$ units long.

Somehow, you are not allowed to look into the box, but you want to know how large the disk is and where in the box bottom the disk is laid. You know that the shape of the disk is a true circle with an integer units of radius, not less than 100 units, and its center is integer units distant from the sides of the box bottom. The radius of the disk is, of course, not greater than the distances of the center of the disk from any of the sides of the box bottom.

You can probe the disk by projecting a thin line segment of light to the box bottom. As the reflection coecients of the disk and the box bottom are quite di↵erent, from the overall reflection intensity, you can tell the length of the part of the segment that lit the disk.

Your task is to decide the exact position and size of the disk through repetitive probes.

# Interaction

You can repeat probes, each of which is a pair of sending a query and receiving the response to it. You can probe at most 1024 times.

A query should be sent to the standard output in the following format, followed by a newline.

query $x _ { 1 } \ y _ { 1 } \ x _ { 2 } \ y _ { 2 }$

Here, $( x _ { 1 } , y _ { 1 } )$ and $( x _ { 2 } , y _ { 2 } )$ are the positions of the two ends of the line segment of the light. They have to indicate distinct points. The coordinate system is such that one of the corners of the box bottom is the origin $( 0 , 0 )$ and the diagonal corner has the coordinates $( 1 0 ^ { 5 } , 1 0 ^ { 5 } )$ . All of $x _ { 1 }$ $y _ { 1 } , x _ { 2 }$ , and $y _ { 2 }$ should be integers between 0 and $1 0 ^ { 5 }$ , inclusive.

In response to this query, a real number is sent back to the standard input, followed by a newline. The number indicates the length of the part of the segment that lit the disk. It is in decimal notation without exponent part, with 7 digits after the decimal point. The number may contain an absolute error up to $1 0 ^ { - 6 }$ .

When you become sure about the position and the size of the disk through the probes, you can send your answer. The answer should have the center position and the radius of the disk. It should be sent to the standard output in the following format, followed by a newline.

answer x y $r$

Here, $( x , y )$ should be the position of the center of the disk, and $r$ the radius of the disk. All of $x$ , $y$ , and $r$ should be integers.

After sending the answer, your program should terminate without any extra output. Thus, you can send the answer only once.

# Notes on interactive judging

When your output violates any of the conditions above (incorrect answer, invalid format, $x _ { 1 }$ , $y _ { 1 }$ , $x _ { 2 }$ , or $y _ { 2 }$ being out of the range, too many queries, any extra output after sending your answer, and so on), your submission will be judged as a wrong answer. As some environments require flushing the output bu↵ers, make sure that your outputs are actually sent. Otherwise, your outputs will never reach the judge.

You are provided with a command-line tool for local testing. For more details, refer to the clarification in the contest system.

# Sample Interaction

![](images/3625dd17dd7f25689dce6182d4cb53a3b711e5676a5a630493e18ccb74aef060.jpg)

![](images/82b051f686b8f6ba8021728785ee1a8b849030cfa832ca9aa75bcb5340411562.jpg)
Figure K.1. Sample Interaction

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

static long long queries = 0;

static const long long query_limit = 1024;

static const long long hard_cap = 20000;

struct Circle {
    long long x, y, r;
} hidden;

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

    }
}

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

double solve_query(long long x1, long long y1, long long x2, long long y2) {

    long double x1d = x1, y1d = y1;
    long double x2d = x2, y2d = y2;
    long double cxd = hidden.x, cyd = hidden.y;
    long double rd = hidden.r;

    long double dx = x2d - x1d;
    long double dy = y2d - y1d;
    long double fx = x1d - cxd;
    long double fy = y1d - cyd;

    long double A = dx * dx + dy * dy;
    long double B = 2.0 * (fx * dx + fy * dy);
    long double C = fx * fx + fy * fy - rd * rd;

    if (A <= 1e-18) return 0.0;

    long double delta = B * B - 4.0 * A * C;

    if (delta < 0) return 0.0;

    long double sqrt_delta = sqrt(delta);
    long double t1 = (-B - sqrt_delta) / (2.0 * A);
    long double t2 = (-B + sqrt_delta) / (2.0 * A);

    long double start = max((long double)0.0, t1);
    long double end = min((long double)1.0, t2);

    if (start < end) {

        return (double)((end - start) * sqrt(A));
    }
    return 0.0;
}

bool in_range(long long val) {
    return val >= 0 && val <= 100000;
}

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

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

    hidden.x = inf.readInt();
    hidden.y = inf.readInt();
    hidden.r = inf.readInt();

    log_metrics();

    cout << fixed << setprecision(7);

    while (true) {

        if (queries > hard_cap) {
            finish(_pe, "Too many queries (hard cap)");
        }

        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (expected query or answer)");
        }

        if (token == "answer" || token == "!") {
            long long ax, ay, ar;
            if (!(cin >> ax >> ay >> ar)) {
                finish(_wa, "Invalid answer format");
            }

            if (ax == hidden.x && ay == hidden.y && ar == hidden.r) {
                finish(_ok, "Correct answer");
            } else {
                string msg = "Wrong answer. Expected: " + to_string(hidden.x) + " "
                           + to_string(hidden.y) + " " + to_string(hidden.r)
                           + ", Found: " + to_string(ax) + " " + to_string(ay) + " " + to_string(ar);
                finish(_wa, msg);
            }
        }
        else {

            long long x1, y1, x2, y2;
            bool explicit_query = (token == "query" || token == "?");

            if (explicit_query) {
                if (!(cin >> x1 >> y1 >> x2 >> y2)) {
                    finish(_wa, "Invalid query format");
                }
            } else {

                try {
                    size_t pos;
                    x1 = stoll(token, &pos);
                    if (pos != token.size()) finish(_wa, "Invalid token in query");
                } catch (...) {
                    finish(_wa, "Invalid token in query");
                }
                if (!(cin >> y1 >> x2 >> y2)) {
                    finish(_wa, "Invalid query format");
                }
            }

            if (!in_range(x1) || !in_range(y1) || !in_range(x2) || !in_range(y2)) {
                finish(_wa, "Query coordinates out of bounds [0, 100000]");
            }
            if (x1 == x2 && y1 == y2) {
                finish(_wa, "Query points must be distinct");
            }

            queries++;

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

            double result = solve_query(x1, y1, x2, y2);
            cout << result << endl;
        }
    }

    return 0;
}

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

static long long queries = 0;
static long long query_limit = 1024;
static bool metrics_logged = false;

void log_metrics() {
    if (metrics_logged) return;
    metrics_logged = true;
    try {
        if (tout.is_open()) {
            tout << "queries=" << queries << endl;
            tout << "query_limit=" << query_limit << endl;
        }
    } catch (...) {}
}

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

typedef long long ll;
typedef long double ld;
const ld EPS = 1e-9;
const int BOX_SIZE = 100000;

struct Circle {
    ll x, y, r;
};

ld get_intersection(const Circle& C, ll x1, ll y1, ll x2, ll y2) {
    ld cx = C.x, cy = C.y, cr = C.r;
    ld dx = x2 - x1;
    ld dy = y2 - y1;
    ld len_sq = dx*dx + dy*dy;

    if (len_sq < EPS) return 0.0;

    ld len = sqrt(len_sq);
    ld ux = dx / len;
    ld uy = dy / len;

    ld t_m = (cx - x1) * ux + (cy - y1) * uy;

    ld mx = x1 + t_m * ux;
    ld my = y1 + t_m * uy;
    ld dist_sq = (cx - mx)*(cx - mx) + (cy - my)*(cy - my);

    if (dist_sq > cr*cr) return 0.0;

    ld chord_half = sqrt(max((ld)0.0, cr*cr - dist_sq));

    ld t_start = t_m - chord_half;
    ld t_end = t_m + chord_half;

    ld inter_start = max(t_start, (ld)0.0);
    ld inter_end = min(t_end, len);

    if (inter_start < inter_end) {
        return inter_end - inter_start;
    }
    return 0.0;
}

vector<Circle> candidates;
const int POOL_SIZE = 5000;

void init_pool(int tx, int ty, int tr) {
    candidates.reserve(POOL_SIZE);

    candidates.push_back({(ll)tx, (ll)ty, (ll)tr});

    mt19937 rng(1337 + tx + ty * 100 + tr);

    auto add_candidate = [&](ll x, ll y, ll r) {
        if (r < 100) return;
        if (x < r || x > BOX_SIZE - r) return;
        if (y < r || y > BOX_SIZE - r) return;
        candidates.push_back({x, y, r});
    };

    for (int i = 0; i < POOL_SIZE * 3 && candidates.size() < POOL_SIZE; ++i) {
        int mode = uniform_int_distribution<int>(0, 100)(rng);
        ll r, x, y;

        if (mode < 20) r = uniform_int_distribution<int>(100, 1000)(rng);
        else if (mode < 40) r = uniform_int_distribution<int>(20000, 50000)(rng);
        else r = uniform_int_distribution<int>(100, 50000)(rng);

        if (mode > 80) {

             int side = uniform_int_distribution<int>(0, 3)(rng);
             if (side == 0) x = r + uniform_int_distribution<int>(0, 500)(rng);
             else if (side == 1) x = BOX_SIZE - r - uniform_int_distribution<int>(0, 500)(rng);
             else x = uniform_int_distribution<int>(r, BOX_SIZE - r)(rng);

             if (side == 2) y = r + uniform_int_distribution<int>(0, 500)(rng);
             else if (side == 3) y = BOX_SIZE - r - uniform_int_distribution<int>(0, 500)(rng);
             else y = uniform_int_distribution<int>(r, BOX_SIZE - r)(rng);
        } else {
             x = uniform_int_distribution<int>(r, BOX_SIZE - r)(rng);
             y = uniform_int_distribution<int>(r, BOX_SIZE - r)(rng);
        }

        add_candidate(x, y, r);
    }
}

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

    int tx = inf.readInt();
    int ty = inf.readInt();
    int tr = inf.readInt();

    init_pool(tx, ty, tr);

    cout << fixed << setprecision(7);

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

            finish(_wa, "Unexpected EOF (expected query or answer)");
        }

        if (token == "query") {
            queries++;

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

            ll x1, y1, x2, y2;
            if (!(cin >> x1 >> y1 >> x2 >> y2)) {
                finish(_wa, "Invalid query format");
            }

            auto valid = [&](ll v) { return v >= 0 && v <= BOX_SIZE; };
            if (!valid(x1) || !valid(y1) || !valid(x2) || !valid(y2)) {
                finish(_wa, "Query coordinates out of bounds");
            }
            if (x1 == x2 && y1 == y2) {
                finish(_wa, "Query points must be distinct");
            }

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

            vector<pair<ld, int>> outcomes;
            outcomes.reserve(candidates.size());
            for (int i = 0; i < (int)candidates.size(); ++i) {
                outcomes.push_back({get_intersection(candidates[i], x1, y1, x2, y2), i});
            }

            sort(outcomes.begin(), outcomes.end(), [](const auto& a, const auto& b){
                return a.first < b.first;
            });

            ld WINDOW = 2.0e-6;
            int max_cnt = 0;
            int best_start = 0;

            int r = 0;
            for (int l = 0; l < (int)outcomes.size(); ++l) {
                while (r < (int)outcomes.size() && outcomes[r].first - outcomes[l].first <= WINDOW + 1e-15) {
                    r++;
                }
                int cnt = r - l;
                if (cnt > max_cnt) {
                    max_cnt = cnt;
                    best_start = l;
                }
            }

            int best_end = best_start + max_cnt;
            ld min_v = outcomes[best_start].first;
            ld max_v = outcomes[best_end - 1].first;
            ld reply = (min_v + max_v) / 2.0;

            vector<Circle> next_pool;
            next_pool.reserve(max_cnt);
            for (int i = best_start; i < best_end; ++i) {
                next_pool.push_back(candidates[outcomes[i].second]);
            }
            candidates = next_pool;

            if (candidates.empty()) finish(_wa, "Judge internal error: empty pool");

            cout << reply << endl;

        } else if (token == "answer") {
            ll ax, ay, ar;
            if (!(cin >> ax >> ay >> ar)) {
                finish(_wa, "Invalid answer format");
            }

            bool mismatch = false;
            for (const auto& c : candidates) {
                if (c.x != ax || c.y != ay || c.r != ar) {
                    mismatch = true;
                    break;
                }
            }

            if (mismatch) {

                finish(_wa, "Answer is ambiguous or incorrect (multiple valid configurations remain)");
            } else {
                finish(_ok, "Correct");
            }

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

    return 0;
}

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

const int BOX_SIZE = 100000;

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

    registerGen(argc, argv, 1);

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

    long long seed_val = 0;
    if (argc > 1) {
        try {
            seed_val = stoll(string(argv[1]));
        } catch (...) {
            seed_val = 0;
        }
    }

    int x, y, r;

    if (seed_val == 1) {

        r = 100;
        x = 100;
        y = 100;
    } else if (seed_val == 2) {

        r = 100;
        x = BOX_SIZE - 100;
        y = BOX_SIZE - 100;
    } else if (seed_val == 3) {

        r = 50000;
        x = 50000;
        y = 50000;
    } else if (seed_val == 4) {

        r = 100;
        x = 50000;
        y = 50000;
    } else if (seed_val == 5) {

        r = 100;
        x = rnd.next(r, BOX_SIZE - r);
        y = rnd.next(r, BOX_SIZE - r);
    } else {

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

            r = rnd.next(100, 1000);
        } else if (type < 80) {

            r = rnd.next(1001, 20000);
        } else {

            r = rnd.next(20001, 50000);
        }

        x = rnd.next(r, BOX_SIZE - r);
        y = rnd.next(r, BOX_SIZE - r);
    }

    if (mode == "non") {
        cout << x << " " << y << " " << r << endl;
    } else if (mode == "adp") {

        cout << x << " " << y << " " << r << endl;
    }

    return 0;
}


This problem is interactive.

We decided to play a game with you and guess the number $x$ ($1 \le x < n$), where you know the number $n$.

You can make queries like this:

* + c: this command assigns $x = x + c$ ($1 \le c < n$) and then returns you the value $\lfloor\frac{x}{n}\rfloor$ ($x$ divide by $n$ and round down).

You win if you guess the current number with no more than $10$ queries.

Interaction

The interaction begins by reading an integer $n$ ($2 < n \le 1000$), which is written in the input data on its own line.

Then you can make no more than $10$ queries. To make a query, print on a separate line:

* + c: this command will assign $x = x + c$ ($1 \le c < n$) and then print $\lfloor\frac{x}{n}\rfloor$ (divide $x$ by $n$ and round down) on a separate line.

Print the answer, like the queries, on a separate line. The answer doesn't count in number of queries. To output it, use the following format:

* ! x: the current value of $x$.

After that, your program should exit.

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().

Note that the interactor is not responsive.

Examples

Input

```
3

1
```

Output

```
+ 1

! 3
```

Input

```
5

0

0

1
```

Output

```
+ 1

+ 1

+ 1

! 5
```

Input

```
10

0

0

1

2
```

Output

```
+ 2

+ 2

+ 3

+ 8

! 20
```

Note

In the first sample initially $x = 2$. After the first query $x = 3$, $\lfloor\frac{x}{n}\rfloor = 1$.

In the second sample also initially $x = 2$. After the first query $x = 3$, $\lfloor\frac{x}{n}\rfloor = 0$. After the second query $x = 4$, $\lfloor\frac{x}{n}\rfloor = 0$. After the third query $x=5$, $\lfloor\frac{x}{n}\rfloor = 1$.

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

using namespace std;

static long long queries = 0;
static long long query_limit = 10;
static const long long HARD_CAP = 200;

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

    }
}

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

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

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

    int n = inf.readInt(3, 1000, "n");

    long long current_x = inf.readLong(1LL, (long long)n - 1, "x");

    cout << n << endl;

    log_metrics();

    while (true) {

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

        string token;

        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF: solution terminated without outputting answer");
        }

        if (token == "!") {

            long long ans;
            if (!(cin >> ans)) {
                finish(_pe, "Expected integer answer after '!'");
            }

            if (ans == current_x) {
                finish(_ok, "Correct answer");
            } else {
                finish(_wa, format("Wrong answer. Expected %lld, found %lld", current_x, ans));
            }
        } else {

            long long c;
            bool parsed_c = false;

            if (token == "+" || token == "?") {
                if (cin >> c) {
                    parsed_c = true;
                } else {
                    finish(_pe, "Expected integer argument for query");
                }
            } else {

                try {
                    size_t idx;
                    c = stoll(token, &idx);
                    if (idx == token.size()) {
                        parsed_c = true;
                    }
                } catch (...) {

                }
            }

            if (!parsed_c) {
                finish(_pe, format("Invalid token '%s'. Expected '+', '?', or a number", token.c_str()));
            }

            if (c < 1 || c >= n) {
                finish(_pe, format("Invalid query argument c=%lld. Constraint: 1 <= c < n (%d)", c, n));
            }

            queries++;
            current_x += c;
            long long response = current_x / n;

            cout << response << endl;

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

    return 0;
}

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

using namespace std;

ofstream tout_stream;

static long long queries = 0;
static long long query_limit = 10;
static int hard_cap = 200;

static void log_metrics() {
    if (tout_stream.is_open()) {
        tout_stream << "queries=" << queries << endl;
        tout_stream << "query_limit=" << query_limit << endl;
        tout_stream.flush();
    }
}

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

    tout_stream.open(argv[2]);

    atexit(log_metrics);

    int n = inf.readInt();

    cout << n << endl;

    log_metrics();

    long long low = 1;
    long long high = n - 1;
    long long current_adder = 0;

    while (true) {
        string token;

        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF: expected '+' or '!'");
        }

        if (token == "!") {
            long long ans;
            if (!(cin >> ans)) {
                finish(_pe, "Expected integer after '!'");
            }

            if (low < high) {
                finish(_wa, format("Solution not unique. Feasible initial x0 in [%lld, %lld], guessed current %lld",
                                   low, high, ans));
            }

            long long expected = low + current_adder;
            if (ans == expected) {
                finish(_ok, "Correct");
            } else {
                finish(_wa, format("Expected %lld, found %lld", expected, ans));
            }

        } else if (token == "+") {
            long long c;
            if (!(cin >> c)) {
                finish(_pe, "Expected integer after '+'");
            }

            if (c < 1 || c >= n) {
                finish(_pe, format("Increment c=%lld out of range [1, %d)", c, n));
            }

            queries++;
            log_metrics();

            if (queries > hard_cap) {
                finish(_pe, "Too many queries (hard cap exceeded)");
            }

            current_adder += c;

            long long r_min = (low + current_adder) / n;
            long long r_max = (high + current_adder) / n;
            long long response = -1;

            if (r_min == r_max) {

                response = r_min;
            } else {

                long long boundary = r_max * n - current_adder;

                long long size_min = max(0LL, (boundary - 1) - low + 1);
                long long size_max = max(0LL, high - boundary + 1);

                if (size_min >= size_max) {
                    response = r_min;
                    high = boundary - 1;
                } else {
                    response = r_max;
                    low = boundary;
                }
            }

            if (low > high) {
                finish(_fail, "Interactor internal error: feasible set became empty");
            }

            cout << response << endl;

        } else {
            finish(_pe, "Invalid token '" + token + "'");
        }
    }

    return 0;
}

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

using namespace std;

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

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

    int seed_val = atoi(argv[1]);

    if (n == -1) {
        if (seed_val == 1) {
            n = 3;
        } else if (seed_val == 2) {
            n = 1000;
        } else if (seed_val == 3) {
            n = 1000;
        } else if (seed_val == 4) {
            n = 4;
        } else if (seed_val == 5) {
            n = 5;
        } else if (seed_val == 6) {
            n = 512;
        } else if (seed_val == 7) {
            n = 997;
        } else if (seed_val >= 8 && seed_val <= 20) {

            n = rnd.next(900, 1000);
        } else {

            n = rnd.next(3, 1000);
        }
    }

    if (n < 3) n = 3;
    if (n > 1000) n = 1000;

    cout << n << endl;

    if (mode == "non") {

        if (x == -1) {
            if (seed_val == 1) {
                x = 1;
            } else if (seed_val == 2) {
                x = n - 1;
            } else if (seed_val == 3) {
                x = 1;
            } else {

                x = rnd.next(1, n - 1);
            }
        }

        if (x < 1) x = 1;
        if (x >= n) x = n - 1;

        cout << x << endl;
    }

    return 0;
}


This is an interactive problem.

ICPC Assiut Community decided to hold a unique chess contest, and you were chosen to control a queen and hunt down the hidden king, while a member of ICPC Assiut Community controls this king.

You compete on an $8\times8$ chessboard, the rows are numerated from top to bottom, and the columns are numerated left to right, and the cell in row $x$ and column $y$ is denoted as $(x, y)$.

In one turn you can move the queen to any of the squares on the same horizontal line, vertical line, or any of the diagonals. For example, if the queen was on square ($4$, $5$), you can move to ($q_1$, $5$), ($4$, $q_1$), ($q_1$, $9-q_1$), or ($q_2$, $q_2+1$) where ($1 \le q_1 \le 8$, $q_1 \ne 4$, $1 \le q_2 \le 7$, $q_2 \ne 4$). Note that the queen cannot stay on its current cell.

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

In one turn, the king can move "Right", "Left", "Up", "Down", "Down-Right", "Down-Left", "Up-Left", or "Up-Right" such that he doesn't get out of the board. The king cannot move into a cell that is on the same row, column or diagonal with the queen (including the position of the queen itself). For example, if the king was on square ($4$, $5$), he can move to ($4+k_1$, $5+k_2$) where ($-1 \le k_1,k_2 \le 1$, $(k_1, k_2) \ne (0, 0)$).

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

At the start of the game, you should place the queen at any location on the board, and this is done once per game. After that the king is secretly placed at any cell different from the queen's location. You do not know the position of the king. Then, the king and the queen take turns with the king moving first. The king moves to one of the possible directions ("Right", "Down", "Up-Left", etc.), and you are only given the direction it moves to. After that, you should move your queen by declaring the square to which your queen will move. The game follows like this until you win the game or run out of moves.

You win if the king has no valid moves. You lose if after $130$ moves of the queen the king still has valid moves.

Input

The first line contains a single integer $t$ ($1 \le t \le 60$) — the number of test cases.

Interaction

In each test case, you should print the queen's starting cell immediately. If you placed the queen at the king's cell, you will win immediately.

After that, you may make at most $130$ moves. Each move is made in the format $x$ $y$, where $x$ and $y$ are two integers ($1 \leq x,y \leq 8$) that denote the new row and column of the queen respectively. Your move should be a valid queen move.

After the initial queen placement and after each move you will receive a string $s$ that represents the direction of the king's move. It will be one of the following: "Right", "Left", "Up", "Down", "Down-Right", "Down-Left", "Up-Left", "Up-Right", or "Done" if you win the game. You should consider "Done" as the end of each test case.

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.

If at any point you make an invalid query or try to make more than $130$ queries for each test case, the game will terminate immediately and you will receive a Wrong Answer verdict.

Example

Input

```
1
Left
Right
Done
```

Output

```
7 5
7 6
7 7
```

Note

In the example, the hidden king was at $(8, 8)$ at the start. The game follows like this:

 ![](https://espresso.codeforces.com/580233bdef883a90b0c5d1071f28abef110cb745.png)  ![](https://espresso.codeforces.com/1e77e8e2850c2a493eb8a12f3ed2e974876dc255.png)

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

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

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

    }
}

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

struct Pos {
    int x = 0;
    int y = 0;
};

static bool in_board(const Pos& p) {
    return 1 <= p.x && p.x <= 8 && 1 <= p.y && p.y <= 8;
}

static bool attacked_by_queen(const Pos& cell, const Pos& queen) {
    return cell.x == queen.x || cell.y == queen.y || (cell.x + cell.y) == (queen.x + queen.y) ||
           (cell.x - cell.y) == (queen.x - queen.y);
}

struct KingMove {
    int dx;
    int dy;
    const char* name;
};

static const KingMove KMOVES[8] = {
    {0, 1, "Right"},
    {0, -1, "Left"},
    {1, 0, "Down"},
    {-1, 0, "Up"},
    {1, 1, "Down-Right"},
    {1, -1, "Down-Left"},
    {-1, -1, "Up-Left"},
    {-1, 1, "Up-Right"},
};

static vector<pair<Pos, const char*>> legal_king_moves(const Pos& king, const Pos& queen) {
    vector<pair<Pos, const char*>> mv;
    for (const auto& m : KMOVES) {
        Pos nxt{king.x + m.dx, king.y + m.dy};
        if (!in_board(nxt)) continue;
        if (attacked_by_queen(nxt, queen)) continue;
        mv.push_back({nxt, m.name});
    }
    return mv;
}

static int mobility(const Pos& king, const Pos& queen) {
    return (int)legal_king_moves(king, queen).size();
}

static pair<Pos, const char*> choose_king_move(const Pos& king, const Pos& queen) {
    auto moves = legal_king_moves(king, queen);
    if (moves.empty()) return {{0, 0}, "Done"};
    int best = -1;
    pair<Pos, const char*> best_move = moves[0];
    for (const auto& cand : moves) {
        int score = mobility(cand.first, queen);
        if (score > best) {
            best = score;
            best_move = cand;
        }
    }
    return best_move;
}

static bool valid_queen_move(const Pos& from, const Pos& to) {
    if (!in_board(to)) return false;
    if (from.x == to.x && from.y == to.y) return false;
    if (from.x == to.x) return true;
    if (from.y == to.y) return true;
    if ((from.x + from.y) == (to.x + to.y)) return true;
    if ((from.x - from.y) == (to.x - to.y)) return true;
    return false;
}

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

    const int t = inf.readInt(1, 60, "t");
    vector<Pos> kings(t);
    for (int tc = 0; tc < t; tc++) {
        kings[tc].x = inf.readInt(1, 8, "king_x");
        kings[tc].y = inf.readInt(1, 8, "king_y");
    }
    if (!inf.seekEof()) finish(_fail, "Unexpected extra tokens in hidden input");

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

    log_metrics();

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

    for (int tc = 0; tc < t; tc++) {
        Pos king = kings[tc];
        Pos queen;
        if (!(cin >> queen.x >> queen.y)) finish(_pe, "Unexpected EOF reading initial queen position");
        if (!in_board(queen)) finish(_wa, "Initial queen position out of board");

        long long moves_used = 0;

        if (queen.x == king.x && queen.y == king.y) {
            cout << "Done\n";
            cout.flush();
            continue;
        }

        while (true) {

            auto mv = choose_king_move(king, queen);
            if (strcmp(mv.second, "Done") == 0) {
                cout << "Done\n";
                cout.flush();
                break;
            }

            king = mv.first;
            cout << mv.second << "\n";
            cout.flush();

            Pos nxt;
            if (!(cin >> nxt.x >> nxt.y)) finish(_pe, "Unexpected EOF reading queen move");
            moves_used++;
            queries++;
            if (queries > hard_cap) finish(_pe, "Hard cap exceeded (possible infinite loop)");
            if (moves_used > 130) finish(_wa, "Exceeded per-test move limit (130)");

            if (!valid_queen_move(queen, nxt)) finish(_wa, "Invalid queen move");
            queen = nxt;

            if (queen.x == king.x && queen.y == king.y) {
                cout << "Done\n";
                cout.flush();
                break;
            }
        }
    }

    finish(_ok, "OK");
}

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

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

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

    }
}

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

struct Pos {
    int x = 0;
    int y = 0;
};

static bool in_board(const Pos& p) {
    return 1 <= p.x && p.x <= 8 && 1 <= p.y && p.y <= 8;
}

static bool attacked_by_queen(const Pos& cell, const Pos& queen) {
    return cell.x == queen.x || cell.y == queen.y || (cell.x + cell.y) == (queen.x + queen.y) ||
           (cell.x - cell.y) == (queen.x - queen.y);
}

struct KingMove {
    int dx;
    int dy;
    const char* name;
};

static const KingMove KMOVES[8] = {
    {0, 1, "Right"},
    {0, -1, "Left"},
    {1, 0, "Down"},
    {-1, 0, "Up"},
    {1, 1, "Down-Right"},
    {1, -1, "Down-Left"},
    {-1, -1, "Up-Left"},
    {-1, 1, "Up-Right"},
};

static vector<pair<Pos, const char*>> legal_king_moves(const Pos& king, const Pos& queen) {
    vector<pair<Pos, const char*>> mv;
    for (const auto& m : KMOVES) {
        Pos nxt{king.x + m.dx, king.y + m.dy};
        if (!in_board(nxt)) continue;
        if (attacked_by_queen(nxt, queen)) continue;
        mv.push_back({nxt, m.name});
    }
    return mv;
}

static int mobility(const Pos& king, const Pos& queen) {
    return (int)legal_king_moves(king, queen).size();
}

static pair<Pos, const char*> choose_king_move(const Pos& king, const Pos& queen) {
    auto moves = legal_king_moves(king, queen);
    if (moves.empty()) return {{0, 0}, "Done"};
    int best = -1;
    pair<Pos, const char*> best_move = moves[0];
    for (const auto& cand : moves) {
        int score = mobility(cand.first, queen);
        if (score > best) {
            best = score;
            best_move = cand;
        }
    }
    return best_move;
}

static bool valid_queen_move(const Pos& from, const Pos& to) {
    if (!in_board(to)) return false;
    if (from.x == to.x && from.y == to.y) return false;
    if (from.x == to.x) return true;
    if (from.y == to.y) return true;
    if ((from.x + from.y) == (to.x + to.y)) return true;
    if ((from.x - from.y) == (to.x - to.y)) return true;
    return false;
}

static Pos choose_initial_king(const vector<Pos>& candidates, const Pos& queen) {
    Pos best = candidates.empty() ? Pos{1, 1} : candidates[0];
    int best_score = -1;
    for (const auto& p : candidates) {
        if (!in_board(p)) continue;

        int score = mobility(p, queen);
        if (score > best_score) {
            best_score = score;
            best = p;
        }
    }
    return best;
}

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

    const int t = inf.readInt(1, 60, "t");
    vector<vector<Pos>> king_sets(t);
    for (int tc = 0; tc < t; tc++) {
        const int m = inf.readInt(1, 64, "m");
        king_sets[tc].reserve(m);
        for (int i = 0; i < m; i++) {
            Pos p;
            p.x = inf.readInt(1, 8, "king_x");
            p.y = inf.readInt(1, 8, "king_y");
            king_sets[tc].push_back(p);
        }
    }
    if (!inf.seekEof()) finish(_fail, "Unexpected extra tokens in adaptive hidden input");

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

    log_metrics();

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

    for (int tc = 0; tc < t; tc++) {
        Pos queen;
        if (!(cin >> queen.x >> queen.y)) finish(_pe, "Unexpected EOF reading initial queen position");
        if (!in_board(queen)) finish(_wa, "Initial queen position out of board");

        Pos king = choose_initial_king(king_sets[tc], queen);
        if (!in_board(king)) finish(_fail, "Internal: chosen king out of board");

        long long moves_used = 0;

        if (queen.x == king.x && queen.y == king.y) {
            cout << "Done\n";
            cout.flush();
            continue;
        }

        while (true) {
            auto mv = choose_king_move(king, queen);
            if (strcmp(mv.second, "Done") == 0) {
                cout << "Done\n";
                cout.flush();
                break;
            }
            king = mv.first;
            cout << mv.second << "\n";
            cout.flush();

            Pos nxt;
            if (!(cin >> nxt.x >> nxt.y)) finish(_pe, "Unexpected EOF reading queen move");
            moves_used++;
            queries++;
            if (queries > hard_cap) finish(_pe, "Hard cap exceeded (possible infinite loop)");
            if (moves_used > 130) finish(_wa, "Exceeded per-test move limit (130)");
            if (!valid_queen_move(queen, nxt)) finish(_wa, "Invalid queen move");
            queen = nxt;

            if (queen.x == king.x && queen.y == king.y) {
                cout << "Done\n";
                cout.flush();
                break;
            }
        }
    }

    finish(_ok, "OK");
}

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

static vector<pair<int,int>> allCells() {
    vector<pair<int,int>> v;
    for (int x = 1; x <= 8; x++)
        for (int y = 1; y <= 8; y++)
            v.push_back({x, y});
    return v;
}

static vector<pair<int,int>> edgeCells() {
    vector<pair<int,int>> v;
    for (int x = 1; x <= 8; x++) {
        for (int y = 1; y <= 8; y++) {
            if (x == 1 || x == 8 || y == 1 || y == 8) v.push_back({x, y});
        }
    }
    return v;
}

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

    string mode = opt<string>("mode", "non");
    long long seedVal = 1;
    if (argc >= 2) {
        try { seedVal = stoll(string(argv[1])); }
        catch (...) { seedVal = 1; }
    }

    if (mode == "non") {
        int kx = opt<int>("kx", -1);
        int ky = opt<int>("ky", -1);

        if (kx == -1 || ky == -1) {
            if (seedVal == 1) {
                kx = 1; ky = 1;
            } else if (seedVal == 2) {
                kx = 1; ky = 4;
            } else if (seedVal == 3) {
                kx = 4; ky = 4;
            } else {

                vector<pair<int,int>> pool;
                for (int x = 2; x <= 7; x++)
                    for (int y = 2; y <= 7; y++)
                        pool.push_back({x, y});
                for (int rep = 0; rep < 6; rep++) {
                    pool.push_back({4,4});
                    pool.push_back({4,5});
                    pool.push_back({5,4});
                    pool.push_back({5,5});
                }
                int idx = rnd.next(0, (int)pool.size() - 1);
                kx = pool[idx].first;
                ky = pool[idx].second;

                if (rnd.next(1, 10) == 1) {
                    vector<pair<int,int>> tricky = {{3,5},{5,3},{6,4},{4,6},{3,4},{4,3},{6,5},{5,6}};
                    auto p = tricky[rnd.next(0, (int)tricky.size() - 1)];
                    kx = p.first; ky = p.second;
                }
            }
        }

        if (!(1 <= kx && kx <= 8 && 1 <= ky && ky <= 8)) {

            kx = 4; ky = 5;
        }

        cout << 1 << "\n";
        cout << kx << " " << ky << "\n";
        return 0;
    }

    if (mode == "adp") {

        vector<pair<int,int>> cells;
        if (seedVal == 1) {

            cells = {{1,1},{1,8},{8,1},{8,8}};
        } else if (seedVal == 2) {

            cells = edgeCells();
        } else {

            cells = allCells();
        }

        if (seedVal > 3) {

            if (rnd.next(1, 5) == 1) {
                int removeCnt = rnd.next(1, 6);
                vector<int> idx(cells.size());
                iota(idx.begin(), idx.end(), 0);
                for (int i = 0; i < removeCnt && (int)cells.size() > 10; i++) {
                    int j = rnd.next(0, (int)idx.size() - 1);
                    int rem = idx[j];
                    idx.erase(idx.begin() + j);

                }

                set<pair<int,int>> forbid;
                int want = removeCnt;
                while (want-- > 0 && (int)forbid.size() < removeCnt) {
                    auto p = cells[rnd.next(0, (int)cells.size() - 1)];
                    forbid.insert(p);
                }
                vector<pair<int,int>> kept;
                kept.reserve(cells.size());
                for (auto &p : cells) if (!forbid.count(p)) kept.push_back(p);
                if (!kept.empty()) cells.swap(kept);
            }
        }

        cout << 1 << "\n";
        cout << (int)cells.size() << "\n";
        for (auto &p : cells) {
            cout << p.first << " " << p.second << "\n";
        }
        return 0;
    }

    cout << 1 << "\n";
    cout << 4 << " " << 5 << "\n";
    return 0;
}


This is an interactive problem.

Emily has a tree containing $n$ nodes, where the weight of the node numbered $i$ is $w _ { i }$ . Node 1 is the root node, and the weight of the root node is $0$ .

Emily wants you to guess the weight of each node. Specifically, you can make at most $n$ queries, with the $i$ -th query containing two integers $u _ { i }$ and $v _ { i }$ . If the simple path from $u _ { i }$ to $v _ { i }$ contains exactly $k$ edges, Emily will tell you the bitwise XOR $^ { \dag }$ of the weights of all the nodes on the simple path from node $u _ { i }$ to node $v _ { i }$ (including the endpoints). Otherwise, Emily will respond with “-1”, indicating that she does not want to answer that question. Emily is very busy, so she will not start answering until you have asked all your questions.

Of course, you may not be able to guess the weights of all nodes with no more than $n$ queries for some cases. In such cases, you should not make any queries and instead directly tell Emily that it is impossible.

†The bitwise XOR operation refers to the addition of each bit of two binary numbers under modulo 2.
For example: $( 0 0 1 1 ) _ { 2 } \oplus ( 0 1 0 1 ) _ { 2 } = ( 0 1 1 0 ) _ { 2 }$ .

# Input

There is only one test case in each test file.

The first line contains two integers $n$ and $k$ ( $2 \leq n \leq 2 5 0$ , $1 \leq k \leq n - 1$ ), representing the number of nodes in the tree and a parameter mentioned in the query.

The next $n - 1$ lines each contain two integers $x _ { i }$ and $y _ { i }$ $1 \leq x _ { i } , y _ { i } \leq n )$ , indicating that there is an edge between nodes $x _ { i }$ and $y _ { i }$ .

It is guaranteed that all edges form a tree, and the correct answer satisfies $0 \leq w _ { i } < 2 ^ { 3 0 }$ .

# Interaction Protocol

First, you need to determine whether it is possible to guess the weights of all nodes within $n$ queries. If not, your program should output “No” and exit immediately. Otherwise, your program should output “Yes” and proceed to querying. You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.

To make a query, output all your $q$ queries at once in the format $^ {  } \ ? \ q \ u _ { 1 } \ v _ { 1 } \ u _ { 2 } \ v _ { 2 } \ \ldots \ u _ { q } \ v _ { q } \ ^ { , * }$ ( $1 \leq q \leq n$ , $1 \leq u _ { i } , v _ { i } \leq n _ { , }$ ). After flushing your output, your program should read a line containing $q$ integers. The $i$ -th integer represents the response to the $i$ -th query.

To guess the weights, output your guess in the format “ ! w2 w3 . . . $w _ { n } \ '$ ” ( $0 \leq w _ { i } < 2 ^ { 3 0 }$ ). After flushing your output, your program should exit immediately.

Note that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also, note that your guess does not count as a query.

To flush your output, you can use:

• fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and $\mathrm { C } + +$

• System.out.flush() in Java and Kotlin.
• stdout.flush() in Python.

# Examples

standard input	standard output

41

12

23

24

	YES

132	？3122324

	！123

52

12

23

34

35

	YES

1234	？413242545

	！4532

62

12

23

34

45

46

	NO

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

static long long queries_count = 0;
static long long query_limit_val = 0;

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

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

string to_lower(string s) {
    for (char &c : s) c = tolower(c);
    return s;
}

int n, k;
vector<pair<int, int>> edges;
vector<vector<int>> adj;
vector<int> hidden_weights;
vector<int> parent_node;
int dist_mat[255][255];

void dfs_setup(int u, int p) {
    parent_node[u] = p;
    for (int v : adj[u]) {
        if (v != p) dfs_setup(v, u);
    }
}

void precompute_dist() {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) dist_mat[i][j] = -1;
        dist_mat[i][i] = 0;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int u = q.front(); q.pop();
            for (int v : adj[u]) {
                if (dist_mat[i][v] == -1) {
                    dist_mat[i][v] = dist_mat[i][u] + 1;
                    q.push(v);
                }
            }
        }
    }
}

vector<int> get_path(int u, int v) {

    vector<int> p_u, p_v;
    int curr = u;
    while (curr) { p_u.push_back(curr); curr = parent_node[curr]; }
    curr = v;
    while (curr) { p_v.push_back(curr); curr = parent_node[curr]; }

    reverse(p_u.begin(), p_u.end());
    reverse(p_v.begin(), p_v.end());

    int lca = 0;
    size_t len = min(p_u.size(), p_v.size());
    for (size_t i = 0; i < len; i++) {
        if (p_u[i] == p_v[i]) lca = p_u[i];
        else break;
    }

    vector<int> res;

    curr = u;
    while (curr != lca) {
        res.push_back(curr);
        curr = parent_node[curr];
    }
    res.push_back(lca);

    vector<int> tmp;
    curr = v;
    while (curr != lca) {
        tmp.push_back(curr);
        curr = parent_node[curr];
    }
    reverse(tmp.begin(), tmp.end());
    res.insert(res.end(), tmp.begin(), tmp.end());

    return res;
}

bitset<256> basis[256];
int basis_sz = 0;

void insert_basis(const bitset<256>& mask) {
    bitset<256> curr = mask;

    for (int i = 0; i < n - 1; i++) {
        if (!curr[i]) continue;
        if (!basis[i].any()) {
            basis[i] = curr;
            basis_sz++;
            return;
        }
        curr ^= basis[i];
    }
}

bool is_solvable() {
    for (int i = 0; i < 256; i++) basis[i].reset();
    basis_sz = 0;

    for (int u = 1; u <= n; u++) {
        for (int v = u + 1; v <= n; v++) {
            if (dist_mat[u][v] == k) {
                vector<int> p = get_path(u, v);
                bitset<256> mask;
                for (int node : p) {
                    if (node >= 2) {

                        mask[node - 2] = 1;
                    }
                }
                insert_basis(mask);
            }
        }
    }

    return (basis_sz == n - 1);
}

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

    n = inf.readInt();
    k = inf.readInt();

    adj.resize(n + 1);
    for (int i = 0; i < n - 1; i++) {
        int u = inf.readInt();
        int v = inf.readInt();
        edges.push_back({u, v});
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    hidden_weights.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        hidden_weights[i] = inf.readInt();
    }

    hidden_weights[1] = 0;

    query_limit_val = n;

    parent_node.resize(n + 1);
    dfs_setup(1, 0);
    precompute_dist();
    bool solvable = is_solvable();

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

    string token;
    if (!(cin >> token)) finish(_wa, "Unexpected EOF while reading YES/NO");
    string s = to_lower(token);

    if (s == "no") {
        if (solvable) finish(_wa, "Contestant said NO, but the weights are uniquely determined");
        else { finish(_ok, "Correctly identified impossible case"); return 0; }
    } else if (s == "yes") {
        if (!solvable) finish(_wa, "Contestant said YES, but the weights are not uniquely determined");
    } else {
        finish(_wa, "Expected 'YES' or 'NO'");
    }

    if (!(cin >> token)) finish(_wa, "Unexpected EOF after YES");

    if (token == "?") {
        int q;
        if (!(cin >> q)) finish(_wa, "Expected query count q after ?");

        if (q < 1 || q > n) finish(_wa, format("Invalid query count %d (must be 1..n)", q));

        queries_count += q;
        log_metrics();

        vector<int> answers;
        for (int i = 0; i < q; i++) {
            int u, v;
            if (!(cin >> u >> v)) finish(_wa, "Expected query pair u v");
            if (u < 1 || u > n || v < 1 || v > n) finish(_wa, "Invalid node index in query");

            if (dist_mat[u][v] == k) {
                int res = 0;
                for (int node : get_path(u, v)) res ^= hidden_weights[node];
                answers.push_back(res);
            } else {
                answers.push_back(-1);
            }
        }

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

        if (!(cin >> token)) finish(_wa, "Expected '!' after query responses");
    }

    if (token != "!") finish(_wa, "Expected '!' to output answer");

    for (int i = 2; i <= n; i++) {
        int w_guess;
        if (!(cin >> w_guess)) finish(_wa, "Expected weight guess");
        if (w_guess != hidden_weights[i]) {
            finish(_wa, format("Wrong weight for node %d. Expected %d, got %d", i, hidden_weights[i], w_guess));
        }
    }

    finish(_ok, "Weights are 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 n = opt<int>("n", -1);
    int k = opt<int>("k", -1);
    int t = opt<int>("t", -1);

    long long seed_val = -1;
    if (argc > 1) {
        string s = argv[1];
        if (s.find_first_not_of("0123456789") == string::npos && s.size() < 18) {
            try {
                seed_val = stoll(s);
            } catch (...) {}
        }
    }

    if (n == -1) {
        if (seed_val == 1) { n = 2; k = 1; t = 1; }
        else if (seed_val == 2) { n = 3; k = 2; t = 2; }
        else if (seed_val == 3) { n = 5; k = 4; t = 1; }
        else if (seed_val == 4) { n = 10; k = 1; t = 0; }
        else if (seed_val != -1 && seed_val <= 10) {
            n = rnd.next(2, 20);
        } else {

            if (rnd.next(5) == 0) n = rnd.next(2, 50);
            else n = rnd.next(200, 250);
        }
    }

    n = max(2, min(250, n));

    if (t == -1) t = rnd.next(5);

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

    if (t == 0) {
        for (int i = 1; i < n; i++)
            edges.push_back({p[i], p[rnd.next(i)]});
    } else if (t == 1) {
        for (int i = 1; i < n; i++)
            edges.push_back({p[i], p[i-1]});
    } else if (t == 2) {
        int center = p[0];
        for (int i = 1; i < n; i++)
            edges.push_back({p[i], center});
    } else if (t == 3) {
        for (int i = 1; i < n; i++)
            edges.push_back({p[i], p[(i-1)/2]});
    } else {
        int len = rnd.next(2, n);

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

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

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

    if (k == -1) {
        int roll = rnd.next(100);
        if (roll < 10) k = 1;
        else if (roll < 20) k = 2;
        else if (roll < 35) k = n - 1;
        else if (roll < 70) k = rnd.next(1, n - 1);
        else k = rnd.next(max(1, n/2), n - 1);
    }

    k = max(1, min(n - 1, k));

    cout << n << " " << k << "\n";

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

    if (mode == "non") {
        vector<int> w(n + 1);
        w[1] = 0;

        for (int i = 2; i <= n; i++) {
            w[i] = rnd.next(0, 1073741823);
        }

        for (int i = 1; i <= n; i++) {
            cout << w[i] << (i == n ? "" : " ");
        }
        cout << "\n";
    }

    return 0;
}


This is an interactive problem.

After emigrating to another country, little Hanna came across the fact that playing “Hot and cold” became more difficult: she does not understand the hint phrases! You are to write a helping program for her.

The playground where the game happens is a rectangle, and the treasure is hidden in some point with integer coordinates between 0 and $1 0 ^ { 6 }$ , inclusive. Hanna visits several points with valid coordinates. If the visited point contains the hidden treasure, she receives the phrase “Found!” in the local language. Fortunately, the intonations allow her to recognize this phrase — in this problem it will be denoted by an exclamation mark.

Otherwise, for each visited point except for the first one, Hanna receives a phrase in the local language stating whether she is now “Closer”, “Further”, or “At the same distance” from the treasure, compared to the previous point. The distances are measured in Euclidean metric. After the first visited point, in case of no treasure there, Hanna receives the phrase “Not found” in the local language.

Your program must help Hanna find the treasure by visiting at most 64 points.

# Interaction Protocol

Your program should print each visited point in a line with two coordinates between 0 and $1 0 ^ { 6 }$ , inclusive, and flush the output after each one.

For each visited point, the testing system writes one of the phrases: “Found!”, “Closer”, “Further”, “At the same distance”, or “Not found” in some language, consistent throughout the game. The first phrase ends with an exclamation mark, all other phrases do not contain exclamation marks. All phrases contain only Latin letters, spaces and exclamation marks, have lengths between 2 and 30, inclusive, don’t start or end with a space, and are pairwise distinct. The phrases are not necessarily coming from any real human language.

After receiving a phrase with an exclamation mark, your program must halt without printing anything else.

# Examples

standard input	standard output

Tabilmadi	500 200

Daha yakin	560 230

Daha yakin	566 240

Sama distanco	566 238

Dalej	30 239

Znaydeno!	566 239

You are lucky today!	777777777777

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

using namespace std;

long long queries = 0;
long long query_limit = 64;
const long long HARD_CAP = 20000;

long long Tx, Ty;
string p_start;
string p_closer;
string p_further;
string p_same;
string p_found;

long long prev_dist_sq = -1;
bool first_query = true;

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

    }
}

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

long long distSq(long long x1, long long y1, long long x2, long long y2) {
    long long dx = x1 - x2;
    long long dy = y1 - y2;
    return dx * dx + dy * dy;
}

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

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

    Tx = inf.readInt();
    Ty = inf.readInt();

    inf.readLine();

    p_start = inf.readLine();
    p_closer = inf.readLine();
    p_further = inf.readLine();
    p_same = inf.readLine();
    p_found = inf.readLine();

    while (true) {

        if (queries > HARD_CAP) {
            finish(_pe, "Hard cap on queries exceeded");
        }

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

            finish(_wa, "Contestant output stream ended without finding treasure");
        }

        long long x, y;
        bool parsed = false;

        if (token == "?" || token == "!") {

            if (cin >> x >> y) parsed = true;
        } else {

            try {
                size_t idx;
                x = stoll(token, &idx);

                if (cin >> y) parsed = true;
            } catch (...) {

                parsed = false;
            }
        }

        if (!parsed) {
            finish(_pe, "Expected integer coordinates, found invalid format");
        }

        if (x < 0 || x > 1000000 || y < 0 || y > 1000000) {
            finish(_pe, format("Point (%lld, %lld) out of valid range [0, 1000000]", x, y));
        }

        queries++;

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

        if (x == Tx && y == Ty) {
            cout << p_found << endl;
            finish(_ok, format("Treasure found at (%lld, %lld) in %lld queries", x, y, queries));
        }

        long long cur_dist_sq = distSq(x, y, Tx, Ty);
        string response;

        if (first_query) {

            response = p_start;
        } else {

            if (cur_dist_sq < prev_dist_sq) {
                response = p_closer;
            } else if (cur_dist_sq > prev_dist_sq) {
                response = p_further;
            } else {
                response = p_same;
            }
        }

        cout << response << endl;

        prev_dist_sq = cur_dist_sq;
        first_query = false;
    }

    return 0;
}

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

using namespace std;

static int queries = 0;
static const int query_limit = 64;
static bool finished = false;

void log_metrics() {

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

    }
}

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

struct Point {
    long long x, y;
};

long long distSq(Point a, Point b) {
    return (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y);
}

string PHRASE_START;
string PHRASE_CLOSER;
string PHRASE_FURTHER;
string PHRASE_SAME;
string PHRASE_FOUND;

bool adaptive_mode = false;
Point hidden_target = {-1, -1};

vector<Point> candidates;
struct HistoryStep {
    Point q;
    int type;
};
vector<HistoryStep> history;

bool is_consistent(Point p, const vector<HistoryStep>& hist) {
    if (hist.empty()) return true;

    if (p.x == hist[0].q.x && p.y == hist[0].q.y) return false;

    for (size_t k = 1; k < hist.size(); ++k) {
        long long d_curr = distSq(p, hist[k].q);
        long long d_prev = distSq(p, hist[k-1].q);

        int type = hist[k].type;
        if (type == 1) {
            if (!(d_curr < d_prev)) return false;
        } else if (type == 2) {
            if (!(d_curr > d_prev)) return false;
        } else if (type == 3) {
            if (!(d_curr == d_prev)) return false;
        }

        if (p.x == hist[k].q.x && p.y == hist[k].q.y) return false;
    }
    return true;
}

void replenish_candidates() {
    if (candidates.empty()) return;

    long long min_x = 1000000, max_x = 0;
    long long min_y = 1000000, max_y = 0;
    for (const auto& p : candidates) {
        min_x = min(min_x, p.x); max_x = max(max_x, p.x);
        min_y = min(min_y, p.y); max_y = max(max_y, p.y);
    }

    min_x = max(0LL, min_x - 10);
    max_x = min(1000000LL, max_x + 10);
    min_y = max(0LL, min_y - 10);
    max_y = min(1000000LL, max_y + 10);

    int attempts = 0;
    while (attempts < 2000 && candidates.size() < 4000) {
        attempts++;
        long long rx = rnd.next(min_x, max_x);
        long long ry = rnd.next(min_y, max_y);
        Point p = {rx, ry};

        if (is_consistent(p, history)) {

            candidates.push_back(p);
        }
    }
}

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

    string line = trim(inf.readLine());
    vector<string> phrases;

    if (!line.empty() && isdigit(line[0])) {

        adaptive_mode = false;
        stringstream ss(line);
        ss >> hidden_target.x >> hidden_target.y;
        for(int i=0; i<5; i++) phrases.push_back(trim(inf.readLine()));
    } else {

        adaptive_mode = true;
        phrases.push_back(line);
        for(int i=0; i<4; i++) phrases.push_back(trim(inf.readLine()));
    }

    PHRASE_START = phrases[0];
    PHRASE_CLOSER = phrases[1];
    PHRASE_FURTHER = phrases[2];
    PHRASE_SAME = phrases[3];
    PHRASE_FOUND = phrases[4];

    if (adaptive_mode) {

        candidates.push_back({0, 0});
        candidates.push_back({0, 1000000});
        candidates.push_back({1000000, 0});
        candidates.push_back({1000000, 1000000});
        for (int i = 0; i < 5000; i++) {
            candidates.push_back({rnd.next(0, 1000000), rnd.next(0, 1000000)});
        }
    }

    Point prev_q = {-1, -1};

    while (true) {

        long long qx, qy;
        if (!(cin >> qx >> qy)) {

            finish(_pe, "Invalid query format or unexpected EOF");
        }

        if (qx < 0 || qx > 1000000 || qy < 0 || qy > 1000000) {
            finish(_pe, "Coordinates out of range");
        }

        queries++;
        Point curr_q = {qx, qy};

        if (adaptive_mode) {

            if (queries == 1) {

                bool all_match = true;
                if (candidates.empty()) all_match = false;
                for (const auto& p : candidates) {
                    if (p.x != qx || p.y != qy) {
                        all_match = false;
                        break;
                    }
                }

                if (all_match && !candidates.empty()) {
                    cout << PHRASE_FOUND << endl;
                    finish(_ok, "Found (forced on query 1)");
                } else {
                    cout << PHRASE_START << endl;
                    history.push_back({curr_q, 0});

                    vector<Point> next_c;
                    for (const auto& p : candidates) {
                        if (p.x != qx || p.y != qy) next_c.push_back(p);
                    }
                    candidates = next_c;
                }
            } else {

                int vote[4] = {0, 0, 0, 0};
                bool can_find = false;

                for (const auto& p : candidates) {
                    if (p.x == qx && p.y == qy) {
                        can_find = true;
                        continue;
                    }

                    long long d_curr = distSq(p, curr_q);
                    long long d_prev = distSq(p, prev_q);

                    if (d_curr < d_prev) vote[1]++;
                    else if (d_curr > d_prev) vote[2]++;
                    else vote[3]++;
                }

                int choice = 0;
                if (vote[1] == 0 && vote[2] == 0 && vote[3] == 0) {
                    if (can_find) {
                        cout << PHRASE_FOUND << endl;
                        finish(_ok, "Found (adaptive)");
                    } else {

                        finish(_wa, "Inconsistent adaptive state (no candidates left)");
                    }
                } else {

                    if (vote[1] >= vote[2] && vote[1] >= vote[3]) choice = 1;
                    else if (vote[2] >= vote[1] && vote[2] >= vote[3]) choice = 2;
                    else choice = 3;

                    if (choice == 1) cout << PHRASE_CLOSER << endl;
                    else if (choice == 2) cout << PHRASE_FURTHER << endl;
                    else cout << PHRASE_SAME << endl;

                    history.push_back({curr_q, choice});

                    vector<Point> next_c;
                    for (const auto& p : candidates) {
                        if (p.x == qx && p.y == qy) continue;

                        long long d_curr = distSq(p, curr_q);
                        long long d_prev = distSq(p, prev_q);

                        bool keep = false;
                        if (choice == 1 && d_curr < d_prev) keep = true;
                        if (choice == 2 && d_curr > d_prev) keep = true;
                        if (choice == 3 && d_curr == d_prev) keep = true;

                        if (keep) next_c.push_back(p);
                    }
                    candidates = next_c;
                }
            }

            if (candidates.size() < 200) {
                replenish_candidates();
            }

        } else {

            if (curr_q.x == hidden_target.x && curr_q.y == hidden_target.y) {
                cout << PHRASE_FOUND << endl;
                finish(_ok, "Found");
            }

            if (queries == 1) {
                cout << PHRASE_START << endl;
            } else {
                long long d_curr = distSq(curr_q, hidden_target);
                long long d_prev = distSq(prev_q, hidden_target);

                if (d_curr < d_prev) cout << PHRASE_CLOSER << endl;
                else if (d_curr > d_prev) cout << PHRASE_FURTHER << endl;
                else cout << PHRASE_SAME << endl;
            }
        }

        prev_q = curr_q;

        if (queries > 200) {
             finish(_pe, "Too many queries (hard cap exceeded)");
        }
    }

    return 0;
}

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

using namespace std;

string generate_phrase(bool isFound) {
    int len = rnd.next(2, 30);
    string s = "";

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

        if (isFound && i == len - 1) {
            s += '!';
            continue;
        }

        bool can_space = true;

        if (i == 0) can_space = false;

        if (isFound && i == len - 2) can_space = false;
        if (!isFound && i == len - 1) can_space = false;

        if (i > 0 && s.back() == ' ') can_space = false;

        if (can_space && rnd.next(6) == 0) {
            s += ' ';
        } else {

            int t = rnd.next(52);
            if (t < 26) s += (char)('a' + t);
            else s += (char)('A' + t - 26);
        }
    }
    return s;
}

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

    string mode = opt<string>("mode", "non");
    long long seed_val = 0;
    if (argc > 1) seed_val = atoll(argv[1]);

    vector<string> phrases;
    while (phrases.size() < 5) {

        bool isFound = (phrases.size() == 4);
        string s = generate_phrase(isFound);

        bool distinct = true;
        for (const string &existing : phrases) {
            if (existing == s) distinct = false;
        }

        if (distinct) {
            phrases.push_back(s);
        }
    }

    if (mode == "non") {

        int MAX_COORD = 1000000;
        int x, y;

        if (seed_val == 1) {
            x = 0; y = 0;
        } else if (seed_val == 2) {
            x = MAX_COORD; y = MAX_COORD;
        } else if (seed_val == 3) {
            x = 0; y = MAX_COORD;
        } else if (seed_val == 4) {
            x = MAX_COORD; y = 0;
        } else if (seed_val == 5) {
            x = MAX_COORD / 2; y = MAX_COORD / 2;
        } else {

            x = rnd.next(0, MAX_COORD);
            y = rnd.next(0, MAX_COORD);
        }

        cout << x << " " << y << "\n";
    }

    for (const string &s : phrases) {
        cout << s << "\n";
    }

    return 0;
}


![](images/5c297e3c3e91fd1e1bdee3a9cfa736e9b7aaa731931354b2ca00f45c9a45b3d5.jpg)

You have reached the final level of the popular roguelike game “Isaac’s Keybindings”. Instead of a boss, you encounter a shopkeeper who holds a hidden array of integers $a _ { 1 } , a _ { 2 } , \ldots , a _ { n }$ , where $0 \leq a _ { i } < 2 ^ { 3 0 }$ for each $i$ in $[ 1 , n ]$ .

It is guaranteed that the array is generated randomly, i.e., $a _ { i }$ is a uniformly random integer in $[ 0 , 2 ^ { 3 0 } )$ for each $i$ in $[ 1 , n ]$ , in all the tests excluding the example.

Let $f ( u , v ) = a _ { u } \oplus a _ { u + 1 } \oplus . . . \oplus a _ { v }$ , where $\bigoplus$ is the bitwise XOR.

You can ask queries of the following form: ? u $\mathtt { v }$ , with $1 \leq u \leq v \leq n$

The answer to the query is:

• $- 1$ , if $f ( u , v ) = 0$ ;
• $\lfloor \log _ { 2 } ( f ( u , v ) ) \rfloor$ otherwise.

Each query has a cost of $\frac { 1 } { v - u + 1 }$ robocoins. You initially have 35 robocoins and if your balance ever becomes negative you lose. Note that your robocoin balance does not need to be an integer at any moment.

Find the answer to all possible n(n+1)2 queries without losing.

# Input

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

The first line of each test case contains one integer $n$ ( $1 \leq n \leq 1 0 0$ ) — the length of the array $a _ { 1 } , a _ { 2 } , \ldots , a _ { n }$ It is guaranteed that the array is generated randomly in all the tests excluding the example.

There are exactly 50 tests in this problem (including the example). The example has $t = 1$ and $n = 3$ and all the other tests have $t = 3 0$ and $n = 1 0 0$ .

# Interaction Protocol

For each test case, first read a single integer $n$ . If the integer you read is $- 2$ , it means that the answer to the previous test case was wrong, and you should exit immediately.

To ask a query, print a line in the format $\ ?$ u v with $1 \leq u \leq v \leq n$

As a response to the query, you will receive $- 2$ if you made an invalid query (i.e., the format is invalid, or you would reach a negative amount of robocoins). In that case, you should exit immediately. Otherwise, you will receive the answer to the query.

When you determine the answers to all the $\frac { n ( n + 1 ) } { 2 }$ queries, print them in the following format.

Print $n + 1$ lines. The first line must contain a single character !. The $i$ -th of the next $n$ lines must contain $n - i + 1$ integers: the answers to queries ? i i, ? i i+1, . . . , ? i n, respectively.

After printing a query, do not forget to output the end of line and flush the output. To do this, use:

• fflush(stdout) or cout.flush() in C++;
• System.out.flush() in Java;
• stdout.flush() in Python;
• see the documentation for other languages.

# Example

standard input	standard output

1

	？12

2

-1	？13

1	？23

	！

	12-1

	21 2

# Note

Explanation of sample 1. In the example, the hidden array is $[ a _ { 1 } , a _ { 2 } , a _ { 3 } ] = [ 2 , 4 , 6 ]$ .

• First, you ask ? 1 2. Since $f ( 1 , 2 ) = a _ { 1 } \oplus a _ { 2 } = 6$ , the answer is $\lfloor \log _ { 2 } ( 6 ) \rfloor = 2$ .
• Then, you ask ? 1 3. Since $f ( 1 , 3 ) = a _ { 1 } \oplus a _ { 2 } \oplus a _ { 3 } = 0$ , the answer is $- 1$ .
• Then, you ask ? 2 3. Since $f ( 2 , 3 ) = a _ { 2 } \oplus a _ { 3 } = 2$ , the answer is $\lfloor \log _ { 2 } ( 2 ) \rfloor = 1$ .

Now, even without knowing the hidden array, you claim the answer to all the possible 6 queries. For example, you claim that the answer to $? \ 1 \ 1$ is 1.

You have spent $\begin{array} { r } { \frac { 1 } { 2 } + \frac { 1 } { 3 } + \frac { 1 } { 2 } = \frac { 4 } { 3 } } \end{array}$ robocoins, which is less than the allowed 35 robocoins.

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

static long long queries = 0;
static long long query_limit = 250000;
static double current_cost = 0.0;
static const double BUDGET = 35.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 int get_msb_index(int x) {
    if (x == 0) return -1;

    return 31 - __builtin_clz(x);
}

void solve_test_case() {

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

    vector<int> pref(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        pref[i+1] = pref[i] ^ a[i];
    }

    cout << n << endl;

    current_cost = 0.0;

    while (true) {
        string token;
        cin >> token;

        if (cin.fail()) {
            finish(_wa, "Unexpected EOF waiting for query or answer token");
        }

        if (token == "!") {

            for (int i = 1; i <= n; ++i) {
                for (int j = i; j <= n; ++j) {
                    int ans;
                    cin >> ans;
                    if (cin.fail()) {
                        finish(_wa, "Unexpected EOF while reading answers");
                    }

                    int val = pref[j] ^ pref[i-1];
                    int expected = (val == 0) ? -1 : get_msb_index(val);

                    if (ans != expected) {
                        cout << "-2" << endl;
                        finish(_wa, "Wrong answer for range [" + to_string(i) + ", " + to_string(j) +
                                    "]. Expected " + to_string(expected) + ", got " + to_string(ans));
                    }
                }
            }

            return;
        } else {

            int u, v;
            bool parsed = false;

            if (token == "?") {
                cin >> u >> v;
                parsed = true;
            } else {
                try {
                    u = stoi(token);
                    cin >> v;
                    parsed = true;
                } catch (...) {
                    parsed = false;
                }
            }

            if (!parsed || cin.fail()) {
                finish(_wa, "Invalid query format");
            }

            queries++;

            if (u < 1 || u > n || v < u || v > n) {
                cout << "-2" << endl;
                finish(_wa, "Query parameters out of bounds: " + to_string(u) + " " + to_string(v));
            }

            double cost = 1.0 / (double)(v - u + 1);
            current_cost += cost;

            if (current_cost > BUDGET + 1e-9) {
                cout << "-2" << endl;
                finish(_wa, "Robocoin budget exceeded (Limit: 35)");
            }

            int val = pref[v] ^ pref[u-1];
            int response = (val == 0) ? -1 : get_msb_index(val);
            cout << response << endl;
        }
    }
}

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

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

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

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

    registerGen(argc, argv, 1);

    long long seed = atoll(argv[1]);

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

    int t;
    if (seed == 1) {
        t = 1;
    } else {
        t = 30;
    }

    cout << t << endl;

    for (int i = 0; i < t; i++) {
        int n;
        vector<int> a;

        if (seed == 1) {

            n = 3;
            a = {2, 4, 6};
        } else {

            n = 100;
            a.resize(n);
            for (int &x : a) {

                x = rnd.next(0, (1 << 30) - 1);
            }
        }

        cout << n << endl;

        if (mode == "non") {

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

    }

    return 0;
}