This is an interactive problem.

A city has $n^2$ buildings divided into a grid of $n$ rows and $n$ columns. You need to build a road of some length $D(A,B)$ of your choice between each pair of adjacent by side buildings $A$ and $B$. Due to budget limitations and legal restrictions, the length of each road must be a positive integer and the total length of all roads should not exceed $48\,000$.

There is a thief in the city who will start from the topmost, leftmost building (in the first row and the first column) and roam around the city, occasionally stealing artifacts from some of the buildings. He can move from one building to another adjacent building by travelling through the road which connects them.

You are unable to track down what buildings he visits and what path he follows to reach them. But there is one tracking mechanism in the city. The tracker is capable of storing a single integer $x$ which is initially $0$. Each time the thief travels from a building $A$ to another adjacent building $B$ through a road of length $D(A,B)$, the tracker changes $x$ to $x\oplus D(A,B)$. Each time the thief steals from a building, the tracker reports the value $x$ stored in it and resets it back to $0$.

It is known beforehand that the thief will steal in exactly $k$ buildings but you will know the values returned by the tracker only after the thefts actually happen. Your task is to choose the lengths of roads in such a way that no matter what strategy or routes the thief follows, you will be able to exactly tell the location of all the buildings where the thefts occurred from the values returned by the tracker.

Interaction

First read a single line containing two integers $n$ $(2\leq n\leq 32)$ and $k$ $(1\leq k\leq 1024)$ denoting the number of rows and number of thefts respectively.

Let's denote the $j$-th building in the $i$-th row by $B_{i,j}$.

Then print $n$ lines each containing $n-1$ integers. The $j$-th integer of the $i$-th line must be the value of $D(B_{i,j},B_{i,j+1})$.

Then print $n-1$ lines each containing $n$ integers. The $j$-th integer of the $i$-th line must be the value of $D(B_{i,j},B_{i+1,j})$.

Remember that the total length of the roads must not exceed $48\,000$.

Then answer $k$ queries. First read the value $x$ returned by the tracker. Then print two integers denoting the row number and column number of the building where the theft occurred. After that you will be able to answer the next query (if such exists).

After printing the answers do not forget to output end of line and flush the output buffer. Otherwise you will get the verdict Idleness limit exceeded. To flush the buffer, use:

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

Example

Input

```
2 4

14

1

14

3
```

Output

```
1
8
2 4

1 2

1 1

1 2

2 1
```

Note

For the sample test, $n=2$ and $k=4$.

You choose to build the roads of the following lengths:

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

The thief follows the following strategy:

1. Start at $B_{1,1}$.
2. Move Right to $B_{1,2}$.
3. Move Down to $B_{2,2}$.
4. Move Left to $B_{2,1}$.
5. Move Up to $B_{1,1}$.
6. Move Right to $B_{1,2}$.
7. Steal from $B_{1,2}$.
8. Move Left to $B_{1,1}$.
9. Steal from $B_{1,1}$.
10. Move Down to $B_{2,1}$.
11. Move Right to $B_{2,2}$.
12. Move Up to $B_{1,2}$.
13. Steal from $B_{1,2}$.
14. Move Left to $B_{1,1}$.
15. Move Down to $B_{2,1}$.
16. Steal from $B_{2,1}$.

The tracker responds in the following way:

1. Initialize $x=0$.
2. Change $x$ to $x\oplus 1=0\oplus1=1$.
3. Change $x$ to $x\oplus 4=1\oplus4=5$.
4. Change $x$ to $x\oplus 8=5\oplus8=13$.
5. Change $x$ to $x\oplus 2=13\oplus2=15$.
6. Change $x$ to $x\oplus 1=15\oplus1=14$.
7. Return $x=14$ and re-initialize $x=0$.
8. Change $x$ to $x\oplus 1=0\oplus1=1$.
9. Return $x=1$ and re-initialize $x=0$.
10. Change $x$ to $x\oplus 2=0\oplus2=2$.
11. Change $x$ to $x\oplus 8=2\oplus8=10$.
12. Change $x$ to $x\oplus 4=10\oplus4=14$.
13. Return $x=14$ and re-initialize $x=0$.
14. Change $x$ to $x\oplus 1=0\oplus1=1$.
15. Change $x$ to $x\oplus 2=1\oplus2=3$.
16. Return $x=3$ and re-initialize $x=0$.

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

using namespace std;

static int queries = 0;
static int query_limit = 0;

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

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

int h_weight[35][35];
int v_weight[35][35];

int N, K;

string readTokenRobust() {
    string s;
    if (!(cin >> s)) {
        finish(_pe, "Unexpected end of output from contestant.");
    }
    if (s == "!") {
        if (!(cin >> s)) finish(_pe, "Unexpected end of output after '!'.");
    }
    return s;
}

int readIntRobust() {
    string s = readTokenRobust();
    try {
        size_t idx;
        int val = stoi(s, &idx);
        if (idx != s.length()) finish(_pe, "Expected integer, found garbage: " + s);
        return val;
    } catch (...) {
        finish(_pe, "Expected integer, found: " + s);
    }
    return 0;
}

int get_xor_path(int r1, int c1, int r2, int c2) {
    if (r1 == r2 && c1 == c2) return 0;

    static int dist[35][35];
    static bool visited[35][35];

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            visited[i][j] = false;
            dist[i][j] = 0;
        }
    }

    queue<pair<int, int>> q;
    q.push({r1, c1});
    visited[r1][c1] = true;
    dist[r1][c1] = 0;

    while (!q.empty()) {
        auto [r, c] = q.front();
        q.pop();

        if (r == r2 && c == c2) return dist[r][c];

        if (c + 1 <= N && !visited[r][c+1]) {
            visited[r][c+1] = true;
            dist[r][c+1] = dist[r][c] ^ h_weight[r][c];
            q.push({r, c+1});
        }

        if (c - 1 >= 1 && !visited[r][c-1]) {
            visited[r][c-1] = true;
            dist[r][c-1] = dist[r][c] ^ h_weight[r][c-1];
            q.push({r, c-1});
        }

        if (r + 1 <= N && !visited[r+1][c]) {
            visited[r+1][c] = true;
            dist[r+1][c] = dist[r][c] ^ v_weight[r][c];
            q.push({r+1, c});
        }

        if (r - 1 >= 1 && !visited[r-1][c]) {
            visited[r-1][c] = true;
            dist[r-1][c] = dist[r][c] ^ v_weight[r-1][c];
            q.push({r-1, c});
        }
    }
    return 0;
}

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

    N = inf.readInt();
    K = inf.readInt();
    query_limit = K;

    vector<pair<int, int>> targets;
    targets.reserve(K);
    for (int i = 0; i < K; ++i) {
        targets.emplace_back(inf.readInt(), inf.readInt());
    }

    cout << N << " " << K << endl;

    long long total_cost = 0;

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j < N; ++j) {
            int w = readIntRobust();
            if (w <= 0) finish(_wa, "Weights must be positive integers.");
            h_weight[i][j] = w;
            total_cost += w;
        }
    }

    for (int i = 1; i < N; ++i) {
        for (int j = 1; j <= N; ++j) {
            int w = readIntRobust();
            if (w <= 0) finish(_wa, "Weights must be positive integers.");
            v_weight[i][j] = w;
            total_cost += w;
        }
    }

    if (total_cost > 48000) {
        finish(_wa, "Total weight " + to_string(total_cost) + " exceeds limit 48000.");
    }

    int cur_r = 1, cur_c = 1;
    log_metrics();

    for (int i = 0; i < K; ++i) {
        int target_r = targets[i].first;
        int target_c = targets[i].second;

        int x = get_xor_path(cur_r, cur_c, target_r, target_c);

        cout << x << endl;

        int r = readIntRobust();
        int c = readIntRobust();

        if (r != target_r || c != target_c) {
            finish(_wa, format("Query %d: Expected (%d, %d), found (%d, %d).", i + 1, target_r, target_c, r, c));
        }

        queries++;
        log_metrics();
        cur_r = target_r;
        cur_c = target_c;
    }

    finish(_ok, format("Passed %d queries.", K));
}

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

using namespace std;

static int queries = 0;
static int query_limit = 0;

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

    }
}

static void finish(TResult verdict, const char* fmt, ...) {
    log_metrics();

    va_list args;
    va_start(args, fmt);
    char buffer[4096];
    vsnprintf(buffer, sizeof(buffer), fmt, args);
    va_end(args);

    quitf(verdict, "%s", buffer);
}

struct Edge {
    int to;
    int weight;
};

int N, K;
vector<pair<int, int>> targets;

vector<vector<Edge>> adj;
long long total_weight = 0;

vector<int> P;
vector<bool> visited;

vector<vector<int>> collisions;

void validate_and_read_grid() {

    for (int r = 0; r < N; r++) {
        for (int c = 0; c < N - 1; c++) {
            int w;
            cin >> w;
            if (cin.fail()) finish(_pe, "Failed to read horizontal edge weight");
            if (w < 1) finish(_wa, "Edge weights must be positive");
            total_weight += w;

            int u = r * N + c;
            int v = r * N + (c + 1);
            adj[u].push_back({v, w});
            adj[v].push_back({u, w});
        }
    }

    for (int r = 0; r < N - 1; r++) {
        for (int c = 0; c < N; c++) {
            int w;
            cin >> w;
            if (cin.fail()) finish(_pe, "Failed to read vertical edge weight");
            if (w < 1) finish(_wa, "Edge weights must be positive");
            total_weight += w;

            int u = r * N + c;
            int v = (r + 1) * N + c;
            adj[u].push_back({v, w});
            adj[v].push_back({u, w});
        }
    }

    if (total_weight > 48000) {
        finish(_wa, "Total weight exceeds 48000");
    }
}

void analyze_graph() {
    P.assign(N * N, -1);
    visited.assign(N * N, false);

    queue<int> q;
    q.push(0);
    P[0] = 0;
    visited[0] = true;

    while(!q.empty()) {
        int u = q.front();
        q.pop();

        for (auto& e : adj[u]) {
            if (!visited[e.to]) {
                visited[e.to] = true;
                P[e.to] = P[u] ^ e.weight;
                q.push(e.to);
            }
        }
    }

    for (int u = 0; u < N * N; u++) {
        if (!visited[u]) {
            finish(_wa, "Graph is not connected");
        }
    }

    map<int, vector<int>> pot_map;
    for (int u = 0; u < N * N; u++) {
        pot_map[P[u]].push_back(u);
    }

    for (auto const& [val, nodes] : pot_map) {
        if (nodes.size() > 1) {
            collisions.push_back(nodes);
        }
    }
}

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

    N = inf.readInt();
    K = inf.readInt();

    query_limit = K;
    log_metrics();

    for (int i = 0; i < K; i++) {
        int r = inf.readInt();
        int c = inf.readInt();
        targets.push_back({r - 1, c - 1});
    }

    cout << N << " " << K << endl;

    adj.resize(N * N);
    validate_and_read_grid();

    analyze_graph();

    int current_node = 0;

    for (int i = 0; i < K; i++) {
        queries++;
        log_metrics();

        int target_node = -1;
        int reported_xor = -1;

        bool using_bad_edge = false;
        bool using_collision = false;
        vector<int> current_collision_set;

        for (auto& e : adj[current_node]) {
            if ((P[current_node] ^ P[e.to]) != e.weight) {
                target_node = e.to;
                reported_xor = e.weight;
                using_bad_edge = true;
                break;
            }
        }

        if (!using_bad_edge && !collisions.empty()) {

            const auto& col_set = collisions[i % collisions.size()];
            current_collision_set = col_set;
            using_collision = true;

            target_node = col_set[0];

            if (target_node == current_node && col_set.size() > 1) {
                target_node = col_set[1];
            }

            reported_xor = P[current_node] ^ P[target_node];
        }

        if (!using_bad_edge && !using_collision) {
            pair<int, int> t = targets[i];
            target_node = t.first * N + t.second;
            reported_xor = P[current_node] ^ P[target_node];
        }

        cout << reported_xor << endl;

        int r, c;
        cin >> r >> c;
        if (cin.fail()) finish(_pe, "Failed to read response coordinates");

        if (r < 1 || r > N || c < 1 || c > N) {
            finish(_wa, "Response coordinates out of bounds: %d %d", r, c);
        }

        int guessed_node = (r - 1) * N + (c - 1);

        if (using_bad_edge) {

            if (guessed_node != target_node) {
                finish(_wa, "Wrong location (inconsistent cycle exploited)");
            }

            current_node = target_node;
        }
        else if (using_collision) {

            if (P[guessed_node] != P[target_node]) {
                finish(_wa, "Wrong location (potential mismatch)");
            }

            bool found_adversarial = false;
            for (int candidate : current_collision_set) {
                if (candidate != guessed_node) {

                    finish(_wa, "Wrong location (ambiguous potentials exploited)");
                }
            }

            current_node = target_node;
        }
        else {

            if (guessed_node != target_node) {
                finish(_wa, "Wrong location. Expected (%d, %d), found (%d, %d)",
                       target_node / N + 1, target_node % N + 1, r, c);
            }
            current_node = target_node;
        }
    }

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

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

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

            int t = rnd.next(100);
            if (t < 5) n = 2;
            else if (t < 15) n = rnd.next(3, 10);
            else if (t < 45) n = rnd.next(11, 30);
            else n = 32;
        }
    }

    if (k == -1) {
        if (seed_val == 1) k = 1;
        else if (seed_val == 2) k = 1024;
        else if (seed_val == 3) k = 1024;
        else {

            int t = rnd.next(100);
            if (t < 5) k = 1;
            else if (t < 15) k = rnd.next(2, 20);
            else if (t < 45) k = rnd.next(21, 500);
            else k = rnd.next(501, 1024);
        }
    }

    cout << n << " " << k << endl;

    if (seed_val == 1 && n == 2 && k == 1) {

        cout << "2 2" << endl;
    } else {

        for (int i = 0; i < k; ++i) {
            cout << rnd.next(1, n) << " " << rnd.next(1, n) << "\n";
        }
    }

    return 0;
}


This is an interactive problem.

Faker is being naughty again. You asked him to create a nice query problem, but he created an interactive problem where he is answering a query instead! Faker hid a permutation from you, and you have to infer some interesting information by interacting with him.

You are given an integer $n$. Faker hid a hidden permutation$^{\text{∗}}$ $p_1, p_2, \ldots, p_{n^2+1}$ of length $n^2+1$. Your goal is to find a monotone subsequence (either increasing or decreasing) of the hidden permutation, with length exactly $n+1$. It can be proved that every permutation of length $n^2 + 1$ contains a monotone subsequence of length $n+1$. For more information about the proof, you can check out this Wikipedia page.

To find it, you can make at most $n$ skyscraper queries to the interactor, which is defined as follows:

* You provide a set of $k$ indices as a strictly increasing sequence: $i_1, i_2, \ldots, i_k$.
* The interactor considers the values of the hidden permutation at these indices: $p_{i_1}, p_{i_2}, \ldots, p_{i_k}$.
* The interactor then returns the indices corresponding to the visible skyscrapers from this set. An index $i_j$ is visible if its value $p_{i_j}$ is greater than the values of all preceding elements in your query, i.e., $p_{i_j} > p_{i_m}$ for all $1 \le m < j$. This is equivalent to finding the indices of the left-to-right maxima of the sequence $(p_{i_1}, \ldots, p_{i_k})$.

After making at most $n$ queries, you must report a valid monotone subsequence of length exactly $n+1$.

Note that the permutation $p$ is fixed before any queries are made and does not depend on the queries.

$^{\text{∗}}$A permutation of length $m$ is an array consisting of $m$ distinct integers from $1$ to $m$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($m=3$ but there is $4$ in the array).

Input

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

The first and only line of each test case contains a single integer $n$ ($1 \le n \le 100$).

It is guaranteed that the sum of $n^2+1$ over all test cases does not exceed $10\,001$.

Interaction

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

To make a query, print a line in the following format:

*? $k \; i_1 \; i_2 \; \ldots \; i_k$

where $k$ is the number of indices in your query ($1 \le k \le n^2+1$), and $i_1, \ldots, i_k$ are the indices themselves, satisfying $1 \le i_1 < i_2 < \ldots < i_k \le n^2+1$. The indices should be presented in sorted order.

In response, the interactor will print a line in the following format:

* $c \; j_1 \; j_2 \; \ldots \; j_c$

where $c$ is the number of visible skyscrapers from your query ($1 \le c \le k$), and $j_1, \ldots, j_c$ are their indices, satisfying $1 \le j_1 < j_2 < \ldots < j_c \le n^2+1$. The indices will be presented in sorted order.

To report your final answer, print a line in the following format:

*! $s_1 \; s_2 \; \ldots \; s_{n+1}$

where $s_1, \ldots, s_{n+1}$ are the indices of the elements that form your found monotone subsequence of length $n+1$, satisfying $1 \le s_1 < s_2 < \ldots < s_{n+1} \le n^2 + 1$. The indices should be presented in sorted order.

Note that answering does not count toward your limit of commands.

After printing the answer, your program should proceed to the next test case or terminate if there are no more.

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 receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

Example

Input

```
2
1

2 1 2

2

1 1

2 2 3
```

Output

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

Note

For the first test case, $n=1$. The hidden permutation is $p=[1, 2]$.

* For the query? 2 1 2, the visible skyscrapers are at indices $1$ and $2$. The interactor returns 2 1 2.
* An increasing subsequence of length $2$ at indices $1, 2$ is reported.

For the second test case, $n=2$. The hidden permutation is $p=[5, 3, 4, 1, 2]$.

* For the query? 3 1 2 3, the visible skyscraper is at index $1$. The interactor returns 1 1.
* For the query? 3 2 3 5, the visible skyscrapers are at indices $2$ and $3$. The interactor returns 2 2 3.
* A decreasing subsequence of length $3$ at indices $1, 3, 4$ is reported.

Although Faker will play the role of interactor, the interactor will never lie to you.

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

static long long readLLFromCinOrFail(const string& what) {
    string tok;
    if (!(cin >> tok)) finish(_pe, "Unexpected EOF while reading " + what);
    if (!isIntegerToken(tok)) finish(_pe, "Non-integer token for " + what);
    long long x = 0;
    try {
        x = stoll(tok);
    } catch (...) {
        finish(_pe, "Integer out of range for " + what);
    }
    return x;
}

static void sendMinusOneAndFail(TResult verdict, const string& msg) {
    cout << -1 << endl;
    cout.flush();
    finish(verdict, msg);
}

static bool isStrictlyIncreasingIndices(const vector<int>& idx, int m) {
    if (idx.empty()) return false;
    if (idx[0] < 1 || idx[0] > m) return false;
    for (int i = 1; i < (int)idx.size(); ++i) {
        if (idx[i] <= idx[i - 1]) return false;
        if (idx[i] < 1 || idx[i] > m) return false;
    }
    return true;
}

static bool isMonotoneByValues(const vector<int>& p, const vector<int>& pos) {
    if ((int)pos.size() <= 2) return true;
    bool inc = true, dec = true;
    for (int i = 1; i < (int)pos.size(); ++i) {
        int a = p[pos[i - 1]];
        int b = p[pos[i]];
        if (!(a < b)) inc = false;
        if (!(a > b)) dec = false;
    }
    return inc || dec;
}

struct CaseData {
    int n;
    int m;
    vector<int> p;
};

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

    int t = inf.readInt(1, 5000, "t");
    vector<CaseData> cases;
    cases.reserve(t);

    long long sumBudget = 0;
    for (int tc = 0; tc < t; ++tc) {
        int n = inf.readInt(1, 100, "n");
        int m = n * n + 1;
        vector<int> p(m + 1, 0);
        for (int i = 1; i <= m; ++i) p[i] = inf.readInt(1, m, "p[i]");
        cases.push_back(CaseData{n, m, std::move(p)});
        sumBudget += n;
    }

    query_limit = sumBudget;
    log_metrics();

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

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

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

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

        while (true) {
            string cmd;
            if (!(cin >> cmd)) finish(_pe, "Unexpected EOF while waiting for command");
            if (cmd == "?") {
                long long kll = readLLFromCinOrFail("k");
                if (kll < 1 || kll > m) sendMinusOneAndFail(_pe, "Invalid k in query");
                int k = (int)kll;

                vector<int> idx(k);
                for (int i = 0; i < k; ++i) {
                    long long v = readLLFromCinOrFail("query index");
                    if (v < INT_MIN || v > INT_MAX) sendMinusOneAndFail(_pe, "Query index out of int range");
                    idx[i] = (int)v;
                }
                if (!isStrictlyIncreasingIndices(idx, m)) sendMinusOneAndFail(_pe, "Query indices not strictly increasing or out of range");

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

                vector<int> visible;
                visible.reserve(k);
                int best = -1;
                for (int id : idx) {
                    int val = p[id];
                    if (val > best) {
                        best = val;
                        visible.push_back(id);
                    }
                }

                cout << (int)visible.size();
                for (int id : visible) cout << " " << id;
                cout << endl;
                cout.flush();
            } else if (cmd == "!") {
                vector<int> ans(n + 1);
                for (int i = 0; i < n + 1; ++i) {
                    long long v = readLLFromCinOrFail("answer index");
                    if (v < INT_MIN || v > INT_MAX) finish(_pe, "Answer index out of int range");
                    ans[i] = (int)v;
                }
                if (!isStrictlyIncreasingIndices(ans, m)) finish(_wa, "Answer indices not strictly increasing or out of range");
                if (!isMonotoneByValues(p, ans)) finish(_wa, "Answer is not a monotone subsequence by values");
                break;
            } else {
                sendMinusOneAndFail(_pe, "Unknown command token");
            }
        }
    }

    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 long long hard_cap = 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 reachable(int start, int target, const vector<vector<int>>& g, vector<int>& vis, int& vid) {
    if (start == target) return false;
    ++vid;
    const int mark = vid;
    deque<int> dq;
    vis[start] = mark;
    dq.push_back(start);
    while (!dq.empty()) {
        int u = dq.front();
        dq.pop_front();
        for (int v : g[u]) {
            if (v == target) return true;
            if (vis[v] == mark) continue;
            vis[v] = mark;
            dq.push_back(v);
        }
    }
    return false;
}

static bool forced_chain(const vector<vector<int>>& g, const vector<int>& s, bool increasing) {

    int m = (int)g.size() - 1;
    vector<int> vis(m + 1, 0);
    int vid = 0;
    for (int i = 0; i + 1 < (int)s.size(); ++i) {
        int a = increasing ? s[i] : s[i + 1];
        int b = increasing ? s[i + 1] : s[i];
        if (!reachable(a, b, g, vis, vid)) return false;
    }
    return true;
}

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

    int t = inf.readInt(1, 5000, "t");
    vector<int> ns(t);
    long long sumN = 0;
    for (int i = 0; i < t; ++i) {
        ns[i] = inf.readInt(1, 100, "n");
        sumN += ns[i];
    }

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

    log_metrics();

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

    for (int tc = 0; tc < t; ++tc) {
        int n = ns[tc];
        int m = n * n + 1;

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

        vector<vector<int>> g(m + 1);

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

            if (cmd == "?") {
                long long kll;
                if (!(cin >> kll)) finish(_pe, "failed to read k");
                if (kll < 1 || kll > m) finish(_pe, "k out of range");

                int k = (int)kll;
                vector<int> idx(k);
                for (int i = 0; i < k; ++i) {
                    long long xll;
                    if (!(cin >> xll)) finish(_pe, "failed to read query index");
                    if (xll < 1 || xll > m) finish(_pe, "query index out of range");
                    idx[i] = (int)xll;
                }
                for (int i = 1; i < k; ++i) {
                    if (idx[i - 1] >= idx[i]) finish(_pe, "query indices not strictly increasing");
                }

                int first = idx[0];
                for (int i = 1; i < k; ++i) {

                    g[idx[i]].push_back(first);
                }

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

                cout << 1 << " " << first << "\n";
                cout.flush();
            } else if (cmd == "!") {
                vector<int> s(n + 1);
                for (int i = 0; i < n + 1; ++i) {
                    long long xll;
                    if (!(cin >> xll)) finish(_pe, "failed to read final answer index");
                    if (xll < 1 || xll > m) finish(_pe, "final answer index out of range");
                    s[i] = (int)xll;
                }
                for (int i = 1; i < n + 1; ++i) {
                    if (s[i - 1] >= s[i]) finish(_pe, "final answer indices not strictly increasing");
                }

                bool ok = false;
                if (n + 1 <= 2) {
                    ok = true;
                } else {
                    if (forced_chain(g, s, true)) ok = true;
                    if (forced_chain(g, s, false)) ok = true;
                }

                if (!ok) finish(_wa, "answer is not guaranteed monotone for all feasible permutations");
                break;
            } else {
                finish(_pe, "unknown command (expected ? or !)");
            }
        }
    }

    finish(_ok, "ok");
}

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

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

static bool isMonotoneByPositions(const vector<int>& p, const vector<int>& pos) {
    if ((int)pos.size() <= 2) return true;
    bool inc = true, dec = true;
    for (int i = 1; i < (int)pos.size(); ++i) {
        int a = p[pos[i - 1]];
        int b = p[pos[i]];
        if (!(a < b)) inc = false;
        if (!(a > b)) dec = false;
    }
    return inc || dec;
}

static bool isMonotoneSegment(const vector<int>& p, int startPos, int len) {
    if (len <= 2) return true;
    bool inc = true, dec = true;
    for (int i = 1; i < len; ++i) {
        int a = p[startPos + i - 1];
        int b = p[startPos + i];
        if (!(a < b)) inc = false;
        if (!(a > b)) dec = false;
    }
    return inc || dec;
}

static vector<int> genHardPerm(int n, bool forceEarlyMaxInFirstGroup) {
    int m = n * n + 1;
    vector<int> p(m + 1, 0);
    p[1] = m;

    int writePos = 2;
    for (int j = n; j >= 1; --j) {
        vector<int> group;
        group.reserve(n);
        for (int b = 0; b < n; ++b) group.push_back(b * n + j);
        shuffleVec(group);

        if (forceEarlyMaxInFirstGroup && j == n) {
            int target = n * n;
            for (int idx = 0; idx < n; ++idx) {
                if (group[idx] == target) {
                    swap(group[0], group[idx]);
                    break;
                }
            }
        }

        for (int x : group) p[writePos++] = x;
    }
    return p;
}

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

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

    int n = opt<int>("n", 100);
    n = max(1, min(100, n));

    if (seedVal == 1) n = 1;
    else if (seedVal == 2) n = 2;
    else if (seedVal == 3) n = 100;
    else {
        int bias = opt<int>("bias", 0);
        if (bias != 0) {
            int lo = max(1, min(100, n - abs(bias)));
            int hi = max(1, min(100, n));
            if (lo > hi) swap(lo, hi);
            n = rnd.next(lo, hi);
        }
    }

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

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

    int m = n * n + 1;
    vector<int> p;

    if (seedVal == 1) {

        p.assign(m + 1, 0);
        p[1] = 2;
        p[2] = 1;
    } else if (seedVal == 2) {

        p.assign(m + 1, 0);
        p[1] = 5;
        p[2] = 2;
        p[3] = 4;
        p[4] = 1;
        p[5] = 3;
    } else {
        bool forceEarlyMax = opt<int>("forceEarlyMax", 1) != 0;

        const int maxAttempts = 2000;
        for (int attempt = 0; attempt < maxAttempts; ++attempt) {
            p = genHardPerm(n, forceEarlyMax);

            bool bad = false;

            if (isMonotoneSegment(p, 1, n + 1)) bad = true;
            if (isMonotoneSegment(p, m - n, n + 1)) bad = true;

            vector<int> groupFirst;
            groupFirst.reserve(n + 1);
            groupFirst.push_back(1);
            for (int t = 0; t < n; ++t) groupFirst.push_back(2 + t * n);
            if (isMonotoneByPositions(p, groupFirst)) bad = true;

            vector<int> groupLast;
            groupLast.reserve(n + 1);
            groupLast.push_back(1);
            for (int t = 0; t < n; ++t) groupLast.push_back(1 + (t + 1) * n + 1);
            if (isMonotoneByPositions(p, groupLast)) bad = true;

            if (m >= (n + 1) * (n + 1)) {
                vector<int> ap;
                ap.reserve(n + 1);
                int step = n + 1;
                int start = 1 + rnd.next(0, min(step - 1, 10));
                for (int k = 0; k <= n; ++k) {
                    int pos = start + k * step;
                    if (pos > m) break;
                    ap.push_back(pos);
                }
                if ((int)ap.size() == n + 1 && isMonotoneByPositions(p, ap)) bad = true;
            }

            if (!bad) break;
        }

        if ((int)p.size() != m + 1) quitf(_fail, "internal generation failed");
    }

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


This is an interactive problem.

You found the numbers $k$ and $n$ in the attic, but lost two arrays $A$ and $B$.

You remember that:

* $|A| + |B| = n$, the total length of the arrays is $n$.
* $|A| \geq k$ and $|B| \geq k$, the length of each array is at least $k$.
* The arrays consist only of numbers from $1$ to $k$.
* If you take any $k$ consecutive elements from array $A$, they will all be different. Also, if you take any $k$ consecutive elements from array $B$, they will all be different.

Fortunately, a kind spirit that settled in the attic found these arrays and concatenated them into an array $C$ of length $n$. That is, the elements of array $A$ were first written into array $C$, followed by the elements of array $B$.

You can ask the kind spirit up to $250$ questions. Each question contains an index $i$ ($1 \leq i \leq n$). In response, you will receive the $i$-th element of the concatenated array $C$.

You need to find the lengths of arrays $A$ and $B$, or report that it is impossible to determine them uniquely.

Input

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

The only line of each test case contains two integers $n$ and $k$ ($1 \leq k \leq 50$, $2 k \leq n \leq 10^{6}$).

Note that the sum of $n$ across test cases is not limited.

Interaction

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

Then you can make up to $250$ queries.

To make a query, output a string in the format "? x" (without quotes) ($1 \leq x \leq n$). After each query, read an integer — the answer to your query.

If you make too many queries, you will receive a verdict of Wrong answer.

To report your answer, output a string in the format "! a b" (without quotes), where $a$ and $b$ are the lengths of arrays $A$ and $B$ that you found, respectively. The answer is not counted when counting the number of queries.

If it is impossible to determine the lengths of the arrays uniquely, output "! -1" (without quotes). Note that if you answer $-1$ while there is a sequence of at most $250$ queries that uniquely determines the lengths of arrays, you will get a Wrong answer verdict.

It is guaranteed that there are arrays $A$ and $B$ that do not contradict the statement, for which the interactor output is correct.

The interactor is not adaptive, which means that the answer is known before the participant makes queries and does not depend on the queries made by the participant.

If your program makes more than $250$ queries, your program should immediately terminate to receive the verdict Wrong answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive a verdict of "IL" (Idleness limit exceeded). To flush the buffer, use:

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

Example

Input

```
6
5 2

1

2

2

18 4

2

4

1

1

4

3 1

10 5

9 3

3

3

2

12 4

1

3

1

3

1

3
```

Output

```
? 1

? 2

? 3

! 2 3

? 9

? 13

? 10

? 14

? 6

! 9 9

! -1

! 5 5

? 3

? 6

? 9

! 6 3

? 1

? 2

? 5

? 6

? 9

? 10

! -1
```

Note

Consider the first example. We queried the first $3$ elements out of $5$. Now we know that the array $C$ looks like $[1, 2, 2, ?, ?]$. We know for sure that the third element is not from array $A$ — because according to the condition, any $k$ consecutive elements (in our case $k = 2$) in array $A$ are different. Thus, the third element is definitely located in array $B$. This means that the length of array $A$ is $2$, and the length of array $B$ is $3$.

The picture shows arrays from all test cases. The elements whose values were requested are marked in yellow.

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

#include "testlib.h"
#include <csignal>
#include <iostream>
#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 bool _all_distinct_window(const vector<int>& c, int start, int k) {
    vector<int> seen(k + 1, 0);
    for (int i = 0; i < k; i++) {
        int x = c[start + i];
        if (x < 1 || x > k) {
            return false;
        }
        if (seen[x]) {
            return false;
        }
        seen[x] = 1;
    }
    return true;
}

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 int per_test_limit = 250;
    query_limit = 1LL * per_test_limit * t;

    for (int tc = 0; tc < t; tc++) {
        const int n = inf.readInt();
        const int k = inf.readInt();
        vector<int> c(n + 1);
        for (int i = 1; i <= n; i++) {
            c[i] = inf.readInt();
        }

        vector<int> bad_eq_prefix(max(0, n - k) + 2, 0);
        for (int i = 1; i + k <= n; i++) {
            bad_eq_prefix[i] = bad_eq_prefix[i - 1] + (c[i] != c[i + k]);
        }

        auto all_eq = [&](int l, int r) -> bool {
            if (l > r) {
                return true;
            }
            if (l < 1) {
                l = 1;
            }
            if (r > n - k) {
                r = n - k;
            }
            return bad_eq_prefix[r] - bad_eq_prefix[l - 1] == 0;
        };

        vector<char> window_distinct(n + 2, 0);
        if (k <= n) {
            vector<int> freq(k + 1, 0);
            int dup = 0;
            for (int i = 1; i <= k; i++) {
                int x = c[i];
                if (x < 1 || x > k) {
                    dup = 1;
                    break;
                }
                freq[x]++;
                if (freq[x] == 2) {
                    dup++;
                }
            }
            window_distinct[1] = (dup == 0);
            for (int s = 2; s + k - 1 <= n; s++) {
                int out = c[s - 1];
                if (1 <= out && out <= k) {
                    if (freq[out] == 2) {
                        dup--;
                    }
                    freq[out]--;
                } else {
                    dup = 1;
                }

                int in = c[s + k - 1];
                if (1 <= in && in <= k) {
                    freq[in]++;
                    if (freq[in] == 2) {
                        dup++;
                    }
                } else {
                    dup = 1;
                }
                window_distinct[s] = (dup == 0);
            }
        }

        vector<int> valid;
        if (n >= 2 * k && k >= 1 && window_distinct[1]) {
            for (int a = k; a <= n - k; a++) {
                if (!all_eq(1, a - k)) {
                    continue;
                }
                if (!window_distinct[a + 1]) {
                    continue;
                }
                if (!all_eq(a + 1, n - k)) {
                    continue;
                }
                valid.push_back(a);
            }
        }

        bool unique = (valid.size() == 1);
        int expected_a = unique ? valid[0] : -1;

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

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

            if (cmd == "?") {
                int x;
                if (!(cin >> x)) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Invalid query");
                }
                used++;
                queries++;
                if (used > per_test_limit) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Too many queries");
                }
                if (queries > query_limit) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Too many queries (overall)");
                }
                if (x < 1 || x > n) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Query index out of range");
                }
                cout << c[x] << "\n" << flush;
                continue;
            }

            if (!cmd.empty() && cmd[0] == '?' && cmd.size() > 1) {
                int x = -1;
                try {
                    x = stoi(cmd.substr(1));
                } catch (...) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Invalid query token");
                }
                used++;
                queries++;
                if (used > per_test_limit) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Too many queries");
                }
                if (queries > query_limit) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Too many queries (overall)");
                }
                if (x < 1 || x > n) {
                    cout << "-1\n" << flush;
                    quit_with(_pe, "Query index out of range");
                }
                cout << c[x] << "\n" << flush;
                continue;
            }

            if (cmd == "!") {
                long long a;
                if (!(cin >> a)) {
                    quit_with(_pe, "Missing answer");
                }
                if (a == -1) {
                    if (unique) {
                        quit_with(_wa, "Answered -1 but unique split exists");
                    }
                    break;
                }
                long long b;
                if (!(cin >> b)) {
                    quit_with(_pe, "Missing b");
                }
                if (a + b != n) {
                    quit_with(_wa, "a+b != n");
                }
                if (!unique) {
                    quit_with(_wa, "Answered lengths but split is not unique");
                }
                if ((int)a != expected_a || (int)b != n - expected_a) {
                    quit_with(_wa, "Wrong lengths");
                }
                break;
            }

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

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

#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");
    bool adaptive = (mode == "adp");

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

    int t;

    if (seed_val >= 1 && seed_val <= 3) {
        t = 5;
    } else {
        t = rnd.next(10, 50);
    }

    cout << t << "\n";

    for (int i = 0; i < t; ++i) {
        int n, k, la;
        vector<int> p, q;

        if (seed_val == 1) {

            k = rnd.next(1, 50);
            n = 2 * k;
            la = k;
            p = rnd.perm(k, 1);
            if (rnd.next(0, 1)) q = p;
            else q = rnd.perm(k, 1);
        } else if (seed_val == 2) {

            k = rnd.next(2, 20);
            n = rnd.next(2 * k + 1, 100);
            la = rnd.next(k, n - k);
            p = rnd.perm(k, 1);
            q = p;
        } else if (seed_val == 3) {

            k = rnd.next(3, 10);
            n = rnd.next(2 * k, 60);
            la = rnd.next(k, n - k);
            p = rnd.perm(k, 1);
            q = p;
            int s = rnd.next(1, k - 1);
            rotate(q.begin(), q.begin() + s, q.end());
        } else {

            int type = rnd.next(1, 100);
            if (type <= 10) {

                k = rnd.next(1, 50);
                n = 2 * k;
            } else if (type <= 40) {

                k = rnd.next(1, 10);
                n = rnd.next(2 * k, 50);
            } else if (type <= 80) {

                k = rnd.next(10, 30);
                n = rnd.next(2 * k, 500);
            } else {

                k = rnd.next(30, 50);
                n = rnd.next(2 * k, 2000);
            }

            la = rnd.next(k, n - k);
            p = rnd.perm(k, 1);

            int rel = rnd.next(1, 100);
            if (rel <= 10) {

                q = p;
            } else if (rel <= 30 && k > 1) {

                q = p;
                int s = rnd.next(1, k - 1);
                rotate(q.begin(), q.begin() + s, q.end());
            } else {

                q = rnd.perm(k, 1);
            }
        }

        if (adaptive) {
            cout << n << " " << k << "\n";
        } else {
            cout << n << " " << k << "\n";

            int lb = n - la;
            vector<int> c(n);

            for (int j = 0; j < la; ++j) {
                c[j] = p[j % k];
            }

            for (int j = 0; j < lb; ++j) {
                c[la + j] = q[j % k];
            }

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

    return 0;
}


The only difference between the easy and hard versions is the constraints on the number of queries.

This is an interactive problem.

Ridbit has a hidden array $a$ of $n$ integers which he wants Ashish to guess. Note that $n$ is a power of two. Ashish is allowed to ask three different types of queries. They are of the form

* AND $i$ $j$: ask for the bitwise AND of elements $a_i$ and $a_j$ $(1 \leq i, j \le n$, $i \neq j)$
* OR $i$ $j$: ask for the bitwise OR of elements $a_i$ and $a_j$ $(1 \leq i, j \le n$, $i \neq j)$
* XOR $i$ $j$: ask for the bitwise XOR of elements $a_i$ and $a_j$ $(1 \leq i, j \le n$, $i \neq j)$

Can you help Ashish guess the elements of the array?

In this version, each element takes a value in the range $[0, n-1]$ (inclusive) and Ashish can ask no more than $n+2$ queries.

Input

The first line of input contains one integer $n$ $(4 \le n \le 2^{16})$ — the length of the array. It is guaranteed that $n$ is a power of two.

Interaction

To ask a query print a single line containing one of the following (without quotes)

* "AND i j"
* "OR i j"
* "XOR i j"

where $i$ and $j$ $(1 \leq i, j \le n$, $i \neq j)$ denote the indices being queried.

For each query, you will receive an integer $x$ whose value depends on the type of query. If the indices queried are invalid or you exceed the number of queries however, you will get $x = -1$. In this case, you should terminate the program immediately.

When you have guessed the elements of the array, print a single line "! " (without quotes), followed by $n$ space-separated integers  — the elements of the array.

Guessing the array does not count towards the number of queries asked.

The interactor is not adaptive. The array $a$ does not change with queries.

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

```
4

0

2

3
```

Output

```
OR 1 2

OR 2 3

XOR 2 4! 0 0 2 3
```

Note

The array $a$ in the example is $[0, 0, 2, 3]$.

#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 isPowerOfTwo(int x) {
    return x > 0 && (x & (x - 1)) == 0;
}

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

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

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

    if (n < 4 || n > (1 << 16) || !isPowerOfTwo(n)) {

        query_limit = 0;
        log_metrics();
        finish(_pe, "Hidden input invalid: n out of bounds or not power of two");
    }

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int v;
        try {
            v = inf.readInt();
        } catch (...) {
            finish(_pe, "Failed to read hidden array");
        }
        a[i] = v;
    }

    query_limit = (long long)n + 2;
    log_metrics();

    cout << n << endl;

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

    auto reply_and_flush = [&](long long x) {
        cout << x << endl;
    };

    string cmd;
    while (true) {
        if (!(cin >> cmd)) {
            finish(_wa, "Contestant terminated without providing final answer");
        }

        if (cmd == "!") {
            vector<long long> ans(n);
            for (int i = 0; i < n; i++) {
                if (!(cin >> ans[i])) {
                    finish(_pe, "Malformed final answer: expected n integers after '!'");
                }
            }
            for (int i = 0; i < n; i++) {
                if (ans[i] != a[i]) {
                    finish(_wa, "Wrong final array");
                }
            }
            finish(_ok, "OK");
        } else if (cmd == "AND" || cmd == "OR" || cmd == "XOR") {
            long long i, j;
            if (!(cin >> i >> j)) {
                reply_and_flush(-1);
                finish(_pe, "Malformed query: expected two indices");
            }

            if (i < 1 || i > n || j < 1 || j > n || i == j) {
                reply_and_flush(-1);
                finish(_pe, "Invalid query indices");
            }

            int x;
            int ai = a[(int)i - 1];
            int aj = a[(int)j - 1];
            if (cmd == "AND") x = (ai & aj);
            else if (cmd == "OR") x = (ai | aj);
            else x = (ai ^ aj);

            queries++;
            if (queries > hard_cap) {
                reply_and_flush(-1);
                finish(_pe, "Hard cap exceeded (possible infinite loop)");
            }

            reply_and_flush(x);
        } else {
            reply_and_flush(-1);
            finish(_pe, "Unknown command");
        }
    }
}

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

static bool isPowerOfTwo(int n) {
    return n > 0 && (n & (n - 1)) == 0;
}

static int ilog2pow2(int n) {
    int k = 0;
    while ((1 << k) < n) k++;
    return k;
}

static int reverseBitsK(int x, int k) {
    int r = 0;
    for (int i = 0; i < k; i++) {
        r = (r << 1) | (x & 1);
        x >>= 1;
    }
    return r;
}

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

static vector<int> genPermutationStructured(int n) {
    int k = ilog2pow2(n);
    int mask = rnd.next(0, n - 1);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int v = reverseBitsK(i, k) ^ mask;
        a[i] = v;
    }
    return a;
}

static void ensureA1NotTooTrivial(vector<int>& a) {
    int n = (int)a.size();
    if (n <= 1) return;
    if (a[0] == 0) {
        for (int i = 1; i < n; i++) {
            if (a[i] != 0) {
                swap(a[0], a[i]);
                break;
            }
        }
    }
}

static vector<int> genDupXorNoZero(int n) {
    vector<int> a(n, 0);
    int a1 = rnd.next(0, n - 1);
    a[0] = a1;

    auto pickNotA1 = [&]() -> int {
        if (n == 1) return a1;
        int v = rnd.next(0, n - 2);
        if (v >= a1) v++;
        return v;
    };

    for (int i = 1; i < n; i++) a[i] = pickNotA1();

    int v1 = pickNotA1();
    int v2 = pickNotA1();
    while (v2 == v1) v2 = pickNotA1();

    int p = rnd.next(1, n - 1);
    int q = rnd.next(1, n - 1);
    while (q == p) q = rnd.next(1, n - 1);

    a[p] = v1;
    a[q] = v1;

    if (n >= 6) {
        int r = rnd.next(1, n - 1);
        while (r == p || r == q) r = rnd.next(1, n - 1);
        int s = rnd.next(1, n - 1);
        while (s == p || s == q || s == r) s = rnd.next(1, n - 1);
        a[r] = v2;
        a[s] = v2;
    }
    return a;
}

static vector<int> genHasZeroXor(int n) {
    vector<int> a(n, 0);
    int a1 = rnd.next(0, n - 1);
    a[0] = a1;
    for (int i = 1; i < n; i++) a[i] = rnd.next(0, n - 1);
    int pos = rnd.next(1, n - 1);
    a[pos] = a1;

    if (n >= 8) {
        int v = rnd.next(0, n - 1);
        for (int t = 0; t < min(12, n - 1); t++) {
            int idx = rnd.next(1, n - 1);
            a[idx] = v;
        }
        a[pos] = a1;
    }
    return a;
}

static vector<int> genRandomArray(int n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) a[i] = rnd.next(0, n - 1);
    return a;
}

static int chooseN(long long seed, int nOpt, int minExp, int maxExp) {
    if (nOpt != -1) {
        ensuref(4 <= nOpt && nOpt <= (1 << 16), "n out of bounds");
        ensuref(isPowerOfTwo(nOpt), "n must be a power of two");
        return nOpt;
    }
    if (seed == 1) return 4;
    if (seed == 2) return 8;
    if (seed == 3) return (1 << 16);

    int e;
    int roll = rnd.next(1, 100);
    if (roll <= 82) e = maxExp;
    else e = rnd.next(minExp, maxExp);
    return 1 << e;
}

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

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

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", -1);
    int minExp = opt<int>("minExp", 2);
    int maxExp = opt<int>("maxExp", 16);
    string pattern = opt<string>("pattern", "auto");

    ensuref(2 <= minExp && minExp <= maxExp && maxExp <= 16, "invalid exp range");

    int n = chooseN(seed, nOpt, minExp, maxExp);

    if (mode == "adp") {
        cout << n << "\n";
        return 0;
    }
    ensuref(mode == "non", "unknown mode: %s", mode.c_str());

    vector<int> a;

    if (seed == 1) {

        n = 4;
        a = {2, 0, 3, 1};
    } else if (seed == 2) {

        n = 8;
        a = {6, 1, 1, 2, 3, 4, 5, 0};
    } else if (seed == 3) {

        n = (1 << 16);
        a.resize(n);
        int mask = 43690;
        for (int i = 0; i < n; i++) a[i] = (i ^ mask);
        ensureA1NotTooTrivial(a);
    } else {

        string use = pattern;
        if (use == "auto") {
            int r = rnd.next(1, 100);
            if (n >= 1024) {
                if (r <= 74) use = "perm";
                else if (r <= 86) use = "dup";
                else if (r <= 94) use = "dup0";
                else use = "rand";
            } else {
                if (r <= 50) use = "perm";
                else if (r <= 70) use = "dup";
                else if (r <= 85) use = "dup0";
                else use = "rand";
            }
        }

        if (use == "perm") {
            if (rnd.next(0, 1) == 0) a = genPermutationShuffle(n);
            else a = genPermutationStructured(n);
            ensureA1NotTooTrivial(a);
        } else if (use == "perm_struct") {
            a = genPermutationStructured(n);
            ensureA1NotTooTrivial(a);
        } else if (use == "dup0") {
            a = genHasZeroXor(n);
        } else if (use == "dup") {
            a = genDupXorNoZero(n);
        } else if (use == "rand") {
            a = genRandomArray(n);
        } else {
            ensuref(false, "unknown pattern: %s", use.c_str());
        }
    }

    ensuref((int)a.size() == n, "internal: array size mismatch");
    for (int i = 0; i < n; i++) {
        ensuref(0 <= a[i] && a[i] <= n - 1, "a[%d]=%d out of range [0,%d]", i, a[i], n - 1);
    }

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


This is an interactive problem.

There are $n$ snakes on the number line. The $i$\-th snake is located at the position $a_i$ and has a speed $s_i$. You know the position of each snake, and that the speed of each snake is an integer from $0$ to $2$ inclusive, but you do not know the exact speed of each snake. It is guaranteed that no two snakes are at the same position.

To figure out the snakes' speed, you may give **up to $3$** instructions. Each instruction should be given in the form of a binary string of length $m$ containing letters L and R ($1 \leq m \leq 4n$). After receiving this instruction, the snakes will move for $m$ seconds. On the $i$\-th second, if $s_i=$L, then all snakes move left for that second. Otherwise, all snakes move right for that second. If two snakes are at the same location at any given point (including if the time is not an integer number of seconds), the faster snake is removed from the board. After all $m$ seconds have passed, you are given the number of remaining snakes, as well as the location of all remaining snakes. Note that each instruction is independent of each other – that means that all snakes are revived and moved to their original positions.

Your task is to find the speed of all snakes. However, it may be the case that it is impossible to find the speed of at least one snake. If this is the case, you must report \-1 instead. You should only output \-1 if it is impossible to figure out the speed of at least one snake, no matter which instructions are given. **If you report \-1 when there are a series of at most $3$ instructions that will uniquely determine the speed of each snake, you will get the Wrong Answer verdict.** Similarly, you will receive the Wrong Answer verdict if you did not report \-1 when the configuration is impossible to determine, even if you correctly guessed the speeds.

Input

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

The first line of each test case contains an integer $n$ – the number of snakes ($2 \leq n \leq 10^5$).

The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \leq a_1<a_2<\ldots<a_n \leq 4n$) – the initial position of all snakes.

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

Interaction

After reading in the position of all snakes, interaction begins. To give an instruction, output a line in the following format:

-   ? s

You should guarantee that $s$ contains only letters L and R, and has length between $1$ and $4n$ inclusive.

The jury will return a line in the following format:

-   $k\:b_1\:b_2\:\ldots\:b_k\:(1 \leq k \leq n, -10^9 \leq b_1<b_2<\ldots<b_k \leq 10^9$)

Here, $k$ is the number of snakes that remain after the full instruction, and $b_1,b_2,\ldots,b_k$ are their final positions.

When you are ready to output the answer, output a line in the following format:

-   If it is impossible to determine the speed of all snakes, output ! -1
-   Otherwise, output ! $s_1$ $s_2$ $\ldots$ $s_n$ ($0 \leq s_i \leq 2$). Here, $s_i$ should denote the speed of the $i$\-th snake as given in the input.

Printing the answer does not count as giving an instruction.

After this, proceed to the next case or terminate the program if this is the last test case.

The interactor is **not** adaptive. This means that the speed of all snakes is fixed in advance and does not change in the interaction process. It is further guaranteed that there exists a solution – that is, the resulting positions of all snakes after movements are consistent with their speeds.

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 receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

$^{\text{∗}}$To flush, use:

-   fflush(stdout) or cout.flush() in C++;
-   sys.stdout.flush() in Python;
-   see the documentation for other languages.

Example

Input

```
7
2
1 2

1 1

2
1 6

2 1 4

3
2 3 4

2 2 4

3
2 3 4

3 5 6 7

5
1 3 8 14 15

5
1 2 3 4 5

4
5 6 7 8
```

Output

```

? L

! 0 1

? LRLL

! 0 1

? RRR

! -1

? RRR

! 1 1 1

! 2 1 0 0 1

! 0 2 2 2 0

! 0 1 2 0

```
Note
**Note**

In the first test case, the speed of the snakes is $0$ and $1$. The program begins by giving the instruction L. The right snake moves from $2$ to $1$ while the left snake does not move. However, since now both snakes occupy the position $1$, the one with the higher speed (the right snake) is removed. Therefore, there is only one snake remaining, and it is at position $1$. At this point, the program decides to guess the speed of snakes as $0$ and $1$, which is correct, so this test case is passed. Note that although the speeds $[0,2]$ would also result in there being $1$ snake at position $1$ at the end, we cannot report $-1$, as we can show there is a series of instructions that will differentiate $[0,2]$ and $[0,1]$.

In the third test case, we conclude that the speed of both the first snake and the third snake is $0$, and we can show there is no way to differentiate the speed of the middle snake between $1$ and $2$. Therefore, reporting \-1 is correct in this case.

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

struct Event {
    long long time2;
    int left;
    int right;
    int remove;
};

struct EventCmp {
    bool operator()(const Event& a, const Event& b) const {
        if (a.time2 != b.time2) return a.time2 > b.time2;
        if (a.left != b.left) return a.left > b.left;
        return a.right > b.right;
    }
};

static void push_event_if_needed(
    priority_queue<Event, vector<Event>, EventCmp>& pq,
    const vector<long long>& pos2,
    const vector<int>& speed,
    int dir,
    long long duration2,
    long long current_time2,
    int left,
    int right
) {
    if (left < 0 || right < 0) return;

    int remove = -1;
    int diff = 0;
    if (dir == 1) {
        if (speed[left] <= speed[right]) return;
        remove = left;
        diff = speed[left] - speed[right];
    } else {
        if (speed[right] <= speed[left]) return;
        remove = right;
        diff = speed[right] - speed[left];
    }
    if (diff <= 0) return;

    long long dist2 =
        (pos2[right] - pos2[left]) + 1LL * dir * (speed[right] - speed[left]) * current_time2;
    if (dist2 < 0) return;

    long long dt2 = dist2 / diff;
    long long t2 = current_time2 + dt2;
    if (t2 > duration2) return;

    pq.push(Event{t2, left, right, remove});
}

static vector<long long> simulate_query(const vector<long long>& a, const vector<int>& speed, const string& ops) {
    int n = (int)a.size();
    vector<long long> pos2(n);
    vector<int> prv(n, -1), nxt(n, -1);
    vector<char> alive(n, 1);
    for (int i = 0; i < n; ++i) {
        pos2[i] = 2LL * a[i];
        prv[i] = i - 1;
        nxt[i] = (i + 1 < n) ? (i + 1) : -1;
    }
    int head = (n > 0) ? 0 : -1;

    vector<pair<char, int>> segs;
    for (char c : ops) {
        if (segs.empty() || segs.back().first != c) segs.push_back({c, 1});
        else segs.back().second++;
    }

    for (const auto& seg : segs) {
        char c = seg.first;
        int len = seg.second;
        int dir = (c == 'R') ? 1 : -1;
        long long duration2 = 2LL * len;

        priority_queue<Event, vector<Event>, EventCmp> pq;
        for (int i = head; i != -1 && nxt[i] != -1; i = nxt[i]) {
            int j = nxt[i];
            push_event_if_needed(pq, pos2, speed, dir, duration2, 0, i, j);
        }

        while (!pq.empty()) {
            Event ev = pq.top();
            pq.pop();
            if (ev.time2 > duration2) break;

            int i = ev.left;
            int j = ev.right;
            if (i < 0 || j < 0) continue;
            if (!alive[i] || !alive[j]) continue;
            if (nxt[i] != j || prv[j] != i) continue;

            int rem = ev.remove;
            if (rem != i && rem != j) {
                finish(_pe, "Internal error: bad remove index");
            }

            alive[rem] = 0;

            long long t2 = ev.time2;
            if (rem == i) {
                int p = prv[i];
                prv[j] = p;
                if (p != -1) nxt[p] = j;
                else head = j;

                prv[i] = nxt[i] = -1;

                if (p != -1) push_event_if_needed(pq, pos2, speed, dir, duration2, t2, p, j);
            } else {
                int q = nxt[j];
                nxt[i] = q;
                if (q != -1) prv[q] = i;

                prv[j] = nxt[j] = -1;

                if (q != -1) push_event_if_needed(pq, pos2, speed, dir, duration2, t2, i, q);
            }
        }

        for (int i = head; i != -1; i = nxt[i]) {
            pos2[i] += 1LL * dir * speed[i] * duration2;
        }
    }

    vector<long long> out;
    for (int i = head; i != -1; i = nxt[i]) {
        if ((pos2[i] & 1LL) != 0) {
            finish(_pe, "Internal error: non-integer position at segment boundary");
        }
        out.push_back(pos2[i] / 2);
    }
    return out;
}

struct ExpectedAnswer {
    bool impossible;
    vector<int> speeds;
};

static ExpectedAnswer compute_expected(const vector<long long>& a, const vector<int>& speed) {
    const int n = (int)a.size();

    vector<long long> L = simulate_query(a, speed, "L");
    vector<long long> LR = simulate_query(a, speed, "LR");
    vector<long long> R = simulate_query(a, speed, "R");

    if (L.size() != LR.size()) {
        finish(_pe, "Internal error: |L| != |LR|");
    }

    vector<int> v(n, -1);
    int ptr = 0;
    for (int i = 0; i < (int)LR.size(); ++i) {
        while (ptr < n && a[ptr] != LR[i]) ptr++;
        if (ptr >= n) finish(_pe, "Internal error: LR position not found in a[]");
        v[ptr] = (int)(a[ptr] - L[i]);
    }

    if (v[0] == -1) finish(_pe, "Internal error: v[0] unset");

    for (int i = 1; i < n; ++i) {
        if (v[i] != -1) continue;
        if (v[i - 1] == 1) {
            if (a[i - 1] + 1 != a[i]) finish(_pe, "Internal error: expected consecutive positions");
            v[i] = 2;
            continue;
        }
        if (v[i - 1] != 0) finish(_pe, "Internal error: expected v[i-1] in {0,1}");
        if (a[i - 1] + 2 == a[i]) {
            v[i] = 2;
            continue;
        }
        if (a[i - 1] + 1 != a[i]) finish(_pe, "Internal error: expected gap 1 or 2");
        if (i + 1 < n && v[i + 1] == -1) {
            v[i + 1] = 2;
        }
    }

    for (int i = 1; i + 1 < n; ++i) {
        if (v[i] == -1 && v[i - 1] == 0 && v[i + 1] == 0 && a[i + 1] - a[i - 1] == 2) {
            return ExpectedAnswer{true, {}};
        }
    }

    for (int i = 1; i < n; ++i) {
        if (v[i] != -1) continue;
        auto it = lower_bound(R.begin(), R.end(), a[i - 1]);
        if (it == R.end()) finish(_pe, "Internal error: lower_bound failed in R");
        int pos = (int)(it - R.begin());
        if (pos + 1 >= (int)R.size()) finish(_pe, "Internal error: pos+1 out of range in R");
        v[i] = (int)(R[pos + 1] - a[i]);
    }

    for (int i = 0; i < n; ++i) {
        if (v[i] < 0 || v[i] > 2) finish(_pe, "Internal error: invalid expected speed");
    }

    return ExpectedAnswer{false, v};
}

static bool validate_ops(const string& s, int n) {
    if ((int)s.size() < 1 || (int)s.size() > 4 * n) return false;
    for (char c : s) {
        if (c != 'L' && c != 'R') return false;
    }
    return true;
}

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

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

    int t = inf.readInt(1, 1000, "t");
    cout << t << endl;
    cout.flush();

    for (int tc = 0; tc < t; ++tc) {
        int n = inf.readInt(2, 100000, "n");
        vector<long long> a(n);
        for (int i = 0; i < n; ++i) a[i] = inf.readInt(1, 4 * n, "a_i");

        vector<int> speed(n);
        for (int i = 0; i < n; ++i) speed[i] = inf.readInt(0, 2, "s_i");

        ExpectedAnswer expected = compute_expected(a, speed);

        cout << n << endl;
        for (int i = 0; i < n; ++i) {
            if (i) cout << " ";
            cout << a[i];
        }
        cout << endl;
        cout.flush();

        int q = 0;
        const int QLIM = 3;
        query_limit += QLIM;
        log_metrics();

        while (true) {
            string tok;
            if (!(cin >> tok)) finish(_wa, "Unexpected EOF from contestant");

            if (tok == "?") {
                string ops;
                if (!(cin >> ops)) finish(_wa, "Bad query format");
                if (q >= QLIM) {
                    cout << -1 << endl;
                    cout.flush();
                    finish(_wa, "Too many queries");
                }
                if (!validate_ops(ops, n)) {
                    cout << -1 << endl;
                    cout.flush();
                    finish(_wa, "Invalid query string");
                }

                vector<long long> resp = simulate_query(a, speed, ops);
                cout << resp.size();
                for (long long x : resp) cout << " " << x;
                cout << endl;
                cout.flush();

                q++;
                queries++;
                if (queries % 200 == 0) log_metrics();
                continue;
            }

            if (!tok.empty() && tok[0] == '?') {
                cout << -1 << endl;
                cout.flush();
                finish(_wa, "Bad query format");
            }

            if (tok == "!") {
                string first_tok;
                if (!(cin >> first_tok)) finish(_wa, "Bad answer format");
                if (first_tok == "-1") {
                    if (!expected.impossible) finish(_wa, "Reported -1 but instance is solvable");
                    break;
                }

                int first_speed = -1;
                try {
                    size_t pos = 0;
                    first_speed = stoi(first_tok, &pos);
                    if (pos != first_tok.size()) finish(_wa, "Bad answer token");
                } catch (...) {
                    finish(_wa, "Bad answer token");
                }

                vector<int> out(n);
                out[0] = first_speed;
                for (int i = 1; i < n; ++i) {
                    if (!(cin >> out[i])) finish(_wa, "Bad answer format");
                }
                for (int i = 0; i < n; ++i) {
                    if (out[i] < 0 || out[i] > 2) finish(_wa, "Speed out of range");
                }
                if (expected.impossible) finish(_wa, "Reported speeds but instance is impossible");
                if (out != expected.speeds) finish(_wa, "Wrong speeds");
                break;
            }

            if (!tok.empty() && tok[0] == '!') finish(_wa, "Bad answer token");
            finish(_wa, "Unexpected token (expected '?' or '!')");
        }
    }

    finish(_ok, "All test cases processed");
    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");
    bool output_speeds = (mode == "non");
    int seed_val = atoi(argv[1]);

    vector<pair<int, pair<vector<int>, vector<int>>>> cases;
    long long sum_n = 0;
    const long long MAX_SUM_N = 100000;
    const int MAX_T = 1000;

    auto add_case = [&](int n, vector<int> a, vector<int> s) {
        cases.push_back({n, {a, s}});
        sum_n += n;
    };

    if (seed_val == 1) {

        add_case(2, {1, 2}, {0, 1});
        add_case(2, {1, 6}, {0, 0});
        add_case(3, {2, 3, 4}, {0, 1, 0});
        add_case(5, {1, 2, 3, 4, 5}, {2, 2, 2, 2, 2});
        add_case(5, {1, 2, 3, 4, 5}, {0, 0, 0, 0, 0});
        add_case(4, {5, 6, 7, 8}, {0, 1, 2, 0});

        {
            int n = 10;
            vector<int> a(n);
            iota(a.begin(), a.end(), 1);
            vector<int> s(n);
            for(int i=0;i<n;++i) s[i] = i%3;
            add_case(n, a, s);
        }

        while(sum_n + 20 <= MAX_SUM_N && cases.size() < MAX_T) {
             int n = rnd.next(2, 20);
             if (sum_n + n > MAX_SUM_N) break;
             vector<int> a = rnd.distinct(n, 4*n);
             for(int &x : a) x++;
             sort(a.begin(), a.end());
             vector<int> s(n);
             for(int &x : s) x = rnd.next(0, 2);
             add_case(n, a, s);
        }
    } else {

        while (sum_n < MAX_SUM_N && cases.size() < MAX_T) {
            long long rem = MAX_SUM_N - sum_n;
            if (rem < 2) break;

            int n_limit = (int)rem;
            int n;
            int type = rnd.next(100);

            if (n_limit >= 10000 && type < 5) {
                n = rnd.next(10000, min(50000, n_limit));
            } else if (n_limit >= 1000 && type < 20) {
                n = rnd.next(1000, min(10000, n_limit));
            } else if (n_limit >= 100 && type < 50) {
                n = rnd.next(100, min(1000, n_limit));
            } else {
                n = rnd.next(2, min(100, n_limit));
            }

            vector<int> a;
            int sparsity = rnd.next(3);
            long long max_pos = 4LL * n;

            if (sparsity == 0) {

                long long range_cap = n + rnd.next(0, n);
                range_cap = min(range_cap, max_pos);
                a = rnd.distinct(n, (int)range_cap);
            } else if (sparsity == 1) {

                a = rnd.distinct(n, (int)max_pos);
            } else {

                long long range_cap = rnd.next((long long)n, max_pos);
                a = rnd.distinct(n, (int)range_cap);
            }

            for(int &x : a) x++;
            sort(a.begin(), a.end());

            vector<int> s(n);
            int pat = rnd.next(5);
            if (pat == 0) fill(s.begin(), s.end(), 0);
            else if (pat == 1) fill(s.begin(), s.end(), 2);
            else if (pat == 2) for(int i=0; i<n; ++i) s[i] = i % 2;
            else if (pat == 3) for(int i=0; i<n; ++i) s[i] = i % 3;
            else for(int &x : s) x = rnd.next(0, 2);

            add_case(n, a, s);
        }
    }

    cout << cases.size() << "\n";
    for (const auto& c : cases) {
        int n = c.first;
        const auto& a = c.second.first;
        const auto& s = c.second.second;

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

        if (output_speeds) {
            for (int i = 0; i < n; ++i) {
                cout << s[i] << (i == n - 1 ? "" : " ");
            }
            cout << "\n";
        }
    }

    return 0;
}


# This is an interactive problem.

After the great success from 2018 to 2024, the Nanjing University of Aeronautics and Astronautics (NUAA) will host the International Collegiate Programming Contest (ICPC) Nanjing regional for the eighth time in a row.

Team Power of Two and team Three Hold Two won the champion title for Tsinghua University in 2018 and 2019. In 2020, 2021, and 2022, team Inverted Cross from Peking University won the three-peat champion titles, while in 2023, another team Reborn as a Vegetable Dog from Peking University won the title. In 2024, team Afterlife from Zhejiang University took the first place.

This year, around 335 teams are participating in the contest. At most 33 gold medals, 66 silver medals, and 99 bronze medals will be awarded (note that these numbers are for reference only). We are looking forward to seeing the participants’ outstanding performance! We also want to express our gratitude for the hard work done by all staff and volunteers for this contest. Thank you all for your great contribution to this contest!

![](images/e9df75b1fe8989a62944d235517cbee122940a20e2dce27ae6aed787c7109ffd.jpg)
Photo taken in the 2023 ICPC Asia Nanjing Regional Contest

In the 2018 contest, problem K, Kangaroo Puzzle, requires the contestants to construct an operation sequence for the game:

The puzzle is a grid with $n$ rows and $m$ columns ( $1 \leq n , m \leq 2 0$ ), and there are some (at least 2) kangaroos standing in the puzzle. The player’s goal is to control them to get together. There are some walls in some cells, and the kangaroos cannot enter the cells with walls. The other cells are empty. The kangaroos can move from an empty cell to an adjacent empty cell in four directions: up, down, left, and right.

There is exactly one kangaroo in every empty cell in the beginning, and the player can control the kangaroos by pressing the buttons U, D, L, R on the keyboard. The kangaroos will move simultaneously according to the button you press.

The contestant needs to construct an operating sequence of at most $5 \times 1 0 ^ { 4 }$ steps consisting of U, D, L, R only to achieve the goal.

In the 2020 contest, problem A, Ah, It’s Yesterday Once More, requires the contestants to construct an input map to hack the following code of the problem described before:

#include
using namespace s t d ;
s t r i n g s = "UDLR" ;
i n t main ( )
{ s r a n d ( time (NULL ) ) ; f o r ( i n t i = 1 ; i <= 5 0 0 0 0 ; i ++) p u t c h a r ( s [ rand ( ) % 4 ] ) ; return 0 ;
}

Furthermore, in the 2021 contest (Problem A, Oops, It’s Yesterday Twice More), the 2022 contest (Problem A, Stop, Yesterday Please No More), the 2023 contest (Problem A, Cool, It’s Yesterday Four Times More), and the 2024 contest (Problem A, Hey, Have You Seen My Kangaroo? ), every year we have a problem related to the kangaroos! We would like to introduce all these problems to you, but if we do so every year, we may have a 500-page statement for one single problem in the 3025 contest. Therefore, we omit them this time. Besides, you may already have seen them in the practice contest.

Now, in the 2025 contest, as everyone expects, the kangaroo problem is back again! We don’t know why problem setters are so obsessed with kangaroos, but the problem is as follows:

You are given a grid with $n$ rows and $m$ columns. There is a hole in the cell on the $i _ { h }$ -th row and the $j _ { h }$ -th column. All other cells are empty and there is one kangaroo standing in each cell.

Similarly, the kangaroos are controlled by pressing the button U, D, L, R on the keyboard. All kangaroos will move simultaneously according to the button pressed. Specifically, for any kangaroo located in the cell on the $i$ -th row and the $j$ -th column, indicated by $( i , j )$ :

1. Button U: it will move to $( i - 1 , j )$ .
2. Button D: it will move to $( i + 1 , j )$ .
3. Button L: it will move to $( i , j - 1 )$ .
4. Button R: it will move to $( i , j + 1 )$ .

If a kangaroo steps onto the hole (that is, $i = i _ { h }$ and $j = j _ { h }$ ) or steps out of the grid, it will be removed from the grid.

The problem is that, the exact value of $i _ { h }$ and $j _ { h }$ is not known. Your task is to find the position of the hole with at most $( n + m + 1 0 )$ queries. For each query, you can press one button (U, D, L, or R). The interactor will output an integer $t$ as the answer, indicating the number of kangaroos remaining after you press the button.

Note that the interactor is not adaptive, meaning that the answer for each test case is pre-determined.

# Input

There are multiple test cases. The first line of the input contains an integer $T$ ( $1 \leq T \leq 1 0 0$ ) indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ ( $3 \leq n , m \leq 3 0 .$ ) indicating the number of rows and columns in the grid.

# Interaction Protocol

To ask a query, output one line. First output ? followed by a space, then print one upper-case English letter (U, D, L, or R). After flushing your output, your program should read a single integer $t$ indicating the answer to your query. Recall that you can ask at most $( n + m + 1 0 )$ queries for a test case.

If you want to guess the position of the hole, output one line. First output ! followed by a space, then print two integers $i _ { h }$ and $j _ { h }$ ( $1 \leq i _ { h } \leq n$ , $1 \leq j _ { h } \leq m$ ) separated by a space indicating the position. After flushing your output, your program should continue processing the next test case, or exit immediately if there are no more test cases. 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 C++.
• System.out.flush() in Java and Kotlin.
• sys.stdout.flush() in Python.

# Example

standard input	standard output

2

34	？L

7	？D

3

43	！23

8	？U

5	？R ！11

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

struct TestCase {
    int n, m;
    int hr, hc;
};

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

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

    int T = inf.readInt();
    vector<TestCase> cases;
    cases.reserve(T);
    for (int i = 0; i < T; i++) {
        int n = inf.readInt();
        int m = inf.readInt();
        int r = inf.readInt();
        int c = inf.readInt();
        cases.push_back({n, m, r, c});

        query_limit += (n + m + 10);
    }

    log_metrics();

    cout << T << endl;

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

    for (int t_idx = 0; t_idx < T; t_idx++) {
        const auto& tc = cases[t_idx];

        cout << tc.n << " " << tc.m << endl;

        vector<pair<int, int>> roos;
        roos.reserve(tc.n * tc.m);
        for (int r = 1; r <= tc.n; r++) {
            for (int c = 1; c <= tc.m; c++) {
                if (r == tc.hr && c == tc.hc) continue;
                roos.push_back({r, c});
            }
        }

        bool case_solved = false;
        while (!case_solved) {
            string token;
            if (!(cin >> token)) {
                finish(_wa, "Unexpected EOF while waiting for query/guess");
            }

            bool is_query = false;
            bool is_guess = false;
            char move_dir = 0;
            int guess_r = -1, guess_c = -1;

            if (token == "!") {

                is_guess = true;
                if (!(cin >> guess_r >> guess_c)) {
                    finish(_wa, "Unexpected EOF reading guess coordinates");
                }
            } else if (token == "?") {

                is_query = true;
                string dir_str;
                if (!(cin >> dir_str)) {
                    finish(_wa, "Unexpected EOF reading query direction");
                }
                if (dir_str.size() != 1) {
                    finish(_pe, "Invalid direction format");
                }
                move_dir = dir_str[0];
            } else {

                if (token.size() == 1 && string("UDLR").find(token) != string::npos) {
                    is_query = true;
                    move_dir = token[0];
                } else {
                    finish(_pe, "Invalid token received: " + token);
                }
            }

            if (is_guess) {
                if (guess_r == tc.hr && guess_c == tc.hc) {
                    case_solved = true;

                } else {
                    finish(_wa, format("Incorrect guess: (%d, %d), expected (%d, %d)",
                                     guess_r, guess_c, tc.hr, tc.hc));
                }
            } else if (is_query) {
                queries++;

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

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

                int dr = 0, dc = 0;
                if (move_dir == 'U') dr = -1;
                else if (move_dir == 'D') dr = 1;
                else if (move_dir == 'L') dc = -1;
                else if (move_dir == 'R') dc = 1;
                else finish(_pe, string("Unknown direction: ") + move_dir);

                int write_idx = 0;
                for (size_t k = 0; k < roos.size(); k++) {
                    roos[k].first += dr;
                    roos[k].second += dc;

                    bool alive = true;

                    if (roos[k].first < 1 || roos[k].first > tc.n) alive = false;
                    if (roos[k].second < 1 || roos[k].second > tc.m) alive = false;

                    if (alive && roos[k].first == tc.hr && roos[k].second == tc.hc) alive = false;

                    if (alive) {
                        roos[write_idx++] = roos[k];
                    }
                }
                roos.resize(write_idx);

                cout << roos.size() << endl;
            }
        }
    }

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

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

struct TestCase {
    int n, m, r, c;
};

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

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

    if (argc > 1) {
        seedVal = atoll(argv[1]);
    }

    vector<TestCase> cases;

    if (seedVal == 1) {

        for (int r = 1; r <= 3; r++) {
            for (int c = 1; c <= 3; c++) {
                cases.push_back({3, 3, r, c});
            }
        }

        cases.push_back({3, 4, 1, 1});
        cases.push_back({3, 4, 1, 4});
        cases.push_back({3, 4, 3, 1});
        cases.push_back({3, 4, 3, 4});

        cases.push_back({4, 3, 1, 1});
        cases.push_back({4, 3, 1, 3});
        cases.push_back({4, 3, 4, 1});
        cases.push_back({4, 3, 4, 3});
    }
    else if (seedVal == 2) {

        int n = 30, m = 30;

        cases.push_back({n, m, 1, 1});
        cases.push_back({n, m, 1, m});
        cases.push_back({n, m, n, 1});
        cases.push_back({n, m, n, m});
        cases.push_back({n, m, n/2, m/2});

        for (int i = 0; i < 15; i++) {
            cases.push_back({n, m, rnd.next(1, n), rnd.next(1, m)});
        }
    }
    else if (seedVal == 3) {

        for (int i = 0; i < 10; i++) {
            cases.push_back({3, 30, rnd.next(1, 3), rnd.next(1, 30)});
        }

        for (int i = 0; i < 10; i++) {
            cases.push_back({30, 3, rnd.next(1, 30), rnd.next(1, 3)});
        }
    }
    else {

        int T = 100;
        for (int i = 0; i < T; i++) {
            int n = rnd.next(3, 30);
            int m = rnd.next(3, 30);
            int r = rnd.next(1, n);
            int c = rnd.next(1, m);
            cases.push_back({n, m, r, c});
        }
    }

    cout << cases.size() << "\n";
    for (const auto& tc : cases) {
        if (mode == "non") {
            cout << tc.n << " " << tc.m << " " << tc.r << " " << tc.c << "\n";
        } else {
            cout << tc.n << " " << tc.m << "\n";
        }
    }

    return 0;
}