This is an interactive problem.
Harry and Hermione are trying to hunt down hoglins which are haunting Hogwarts. There is a long hallway in Hogwarts, consisting of  $n$  individual cells, numbered from 1 to  $n$  from the left to the right.
Hermione can cast a spell that would block any cell of the hallway of her choosing. After the spell is cast, the blocked cell will remain blocked while she casts other spells.
Hoglins are simple creatures; all they do is randomly move around and bump into stuff. To be more precise, every hoglin has a range which it considers to be accessible. Initially, when the hoglin appears, it is a range from the cell 1 to the cell  $n$ .
Initially, a single hoglin appears in a cell of the hallway chosen uniformly at random. Then, until this hoglin is caught, the following happens on every round of the hunt:
- Hermione can cast a spell to block any single cell of her choosing, or do nothing.
- If the cell she is trying to block is the cell with a hoglin in it, the hoglin is caught. After that, all the blocked cells become free again, and, if there are more hoglins to be caught, a new hoglin immediately appears in a random location, and the hunt begins again.
- Otherwise, the hoglin chooses a cell uniformly at random from its accessible range and tries to move to that cell, moving one cell at a time towards a chosen cell. Regardless of the distance, all the steps of the movement, as described below, happen in the same round.
- If the chosen cell is to the right of the hoglin, it moves to the right; if the chosen cell is to the left of the hoglin, it moves to the left. If the chosen cell is the same as where the hoglin is now, it does nothing.
- If at any point during the movement towards the chosen cell a hoglin is trying to move to the right or to the left from an unblocked cell at position  $i$  to the neighbouring blocked cell at position  $i \pm 1$ , the hoglin updates the right or left boundary of its accessible range correspondingly to be  $i$ .
- If on the way to the chosen cell, the hoglin tries to move to a blocked cell, Harry and Hermione hear a loud sound, as the hoglin bumps into the blocked cell. In this case, the hoglin returns to the position it has originally started from at the beginning of this round.
- Otherwise, if the hoglin does not bump into any blocked cells on its way, it does not change its accessible range and stays at the new position. In that case, Harry and Hermione hear nothing.
To free Hogwarts from hoglins, Harry and Hermione should catch  $k$  of them, but they don't have much time. They can only afford to hunt hoglins for at most 200 000 rounds. Please help them find an efficient strategy to do that.
# Interaction Protocol
First, the testing system will write two integers  $n$  and  $k$  ( $1 \leq n \leq 10^{18}$ ;  $1 \leq k \leq 800$ ) — the number of cells in Hogwarts' hallway and the number of hoglins that should be caught. Then the catching process begins.
The following interaction proceeds in rounds as described in the problem statement.
At the start of each round, your program should output Hermione's action — an integer  $p$  ( $0 \leq p \leq n$ ) representing the position of the cell Hermione is going to block. If  $p = 0$  or the cell at position  $p$  is already blocked, she does nothing in this round.
Then, if the current position of the hoglin is at the newly blocked cell  $p$ , the hoglin is caught; the testing system outputs 2, all the blocked cells become free, and interaction rounds start again. In case you caught the  $k$ -th hoglin, the testing system outputs 3 instead of 2, and your program should immediately stop execution.
Otherwise, the hoglin attempts to move according to the rules described in the problem statement. If in the process it bumps into any blocked cell, the testing system outputs 1; otherwise, it outputs 0.
If your 200 000-th action does not catch the  $k$ -th hoglin, the testing system outputs -1 instead of its usual answer, and your program should immediately stop execution to guarantee the "Wrong Answer" verdict.
The interactor in this problem is not adaptive. It is guaranteed that the hoglins follow the rules described in the problem statement. The starting cell for each hoglin is chosen uniformly at random and their moves are chosen uniformly at random from the range of cells that they consider accessible.
The problem has at most 15 tests.
Here is the summary of all possible interactor answers:
- -1 — too many actions;
- 0 - hoglin moved successfully, did not bump;
- 1 - hoglin attempted to move, bumped into blocked cell;
- 2 - hoglin is caught, interaction starts again;
- 3 - hoglin is caught, stop.

Example

standard input	standard output	Illustration

9 2		1 2 3 4 5 6 7 8 9

0	3	start at 8block 3move to 4, successblock 7move to 9, bumpedblock 5move to 3, bumpedblock 1move to 4, successblock 9move to 5, bumpedblock 4, caught

1	7

1	5

1	1

0	9

1	4

2	5

1	7

0	0

0	2

3

# Note
We show the sample from the point of view of the hoglins.
The black dot shows the current position of the hoglin.
Crosses mark blocked cells.
White cells mark the range which the hoglin considers to be accessible; other cells are marked gray.
On the right is the action that was performed by either Hermione or the hoglin to get to this state from the previous one.

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

using namespace std;

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

static long long n;
static int k;
static long long seed_val;
static int caught_count = 0;

static long long cur_pos;
static long long range_L, range_R;
static set<long long> blocked;

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

void spawn_hoglin() {

    cur_pos = rnd.next(1LL, n);

    range_L = 1;
    range_R = n;

    blocked.clear();
}

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

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

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

    if (!inf.seekEof()) {
        seed_val = inf.readLong();
    } else {
        seed_val = 847204852305LL;
    }

    rnd.setSeed(seed_val);

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

    spawn_hoglin();

    while (true) {

        if (queries > query_limit + 10) {
            finish(_pe, "Hard query limit exceeded (safety cap)");
        }

        string token;
        if (!(cin >> token)) {
            finish(_pe, "Unexpected end of file from contestant");
        }

        long long p = -1;

        if (token == "!") {
            finish(_pe, "Protocol violation: unexpected '!' token");
        } else if (token == "?") {
            if (!(cin >> p)) finish(_pe, "Expected integer after '?'");
        } else {
            try {
                p = stoll(token);
            } catch (...) {
                finish(_pe, "Invalid integer format");
            }
        }

        if (p < 0 || p > n) {
            finish(_pe, format("Position %lld out of range [0, %lld]", p, n));
        }

        queries++;

        bool newly_blocked = false;
        if (p != 0) {
            if (blocked.find(p) == blocked.end()) {
                blocked.insert(p);
                newly_blocked = true;
            }
        }

        if (newly_blocked && p == cur_pos) {
            caught_count++;
            if (caught_count == k) {
                cout << 3 << endl;
                finish(_ok, format("Caught %d hoglins in %lld queries", k, queries));
            } else {
                cout << 2 << endl;
                spawn_hoglin();
                continue;
            }
        }

        if (queries >= query_limit) {
            cout << -1 << endl;
            finish(_wa, "Query limit exceeded without catching required hoglins");
        }

        long long target = rnd.next(range_L, range_R);

        if (target == cur_pos) {

            cout << 0 << endl;
        } else {
            bool bumped = false;
            long long collider = -1;

            if (target > cur_pos) {

                auto it = blocked.upper_bound(cur_pos);
                if (it != blocked.end() && *it <= target) {
                    bumped = true;
                    collider = *it;

                    range_R = collider - 1;
                }
            } else {

                auto it = blocked.lower_bound(cur_pos);
                if (it != blocked.begin()) {
                    it--;
                    if (*it >= target) {
                        bumped = true;
                        collider = *it;

                        range_L = collider + 1;
                    }
                }
            }

            if (bumped) {

                cout << 1 << endl;
            } else {

                cur_pos = target;
                cout << 0 << endl;
            }
        }
    }

    return 0;
}

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

using namespace std;

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

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

    long long n = 10;
    int k = 1;

    int seed_idx = 0;
    if (argc > 1) {
        string s = argv[1];
        if (!s.empty() && all_of(s.begin(), s.end(), ::isdigit)) {
            try {
                seed_idx = stoi(s);
            } catch (...) {
                seed_idx = 0;
            }
        }
    }

    if (n_opt != -1) {
        n = n_opt;
    } else {

        if (seed_idx == 1) {
            n = 1;
        } else if (seed_idx == 2) {
            n = 1000000000000000000LL;
        } else if (seed_idx == 3) {
            n = 10;
        } else {

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

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

                int e = rnd.next(3, 18);
                long long low = 1;
                for (int i = 0; i < e; ++i) low *= 10;

                long long high;
                if (e >= 18) {

                    low = 100000000000000000LL;
                    high = 1000000000000000000LL;
                } else {
                    high = low * 10 - 1;
                }

                if (high > 1000000000000000000LL) high = 1000000000000000000LL;
                if (low > high) low = high;

                n = rnd.next(low, high);
            } else {

                n = rnd.next(100000000000000000LL, 1000000000000000000LL);

                if (rnd.next(1, 10) == 1) {
                    int p = rnd.next(50, 60);
                    unsigned long long p2 = (1ULL << p);
                    if (p2 <= 1000000000000000000ULL) n = (long long)p2;
                }
            }
        }
    }

    if (k_opt != -1) {
        k = k_opt;
    } else {
        if (seed_idx == 1) {
            k = 1;
        } else if (seed_idx == 2) {
            k = 800;
        } else if (seed_idx == 3) {
            k = 800;
        } else {

            int type = rnd.next(1, 100);
            if (type <= 5) k = 1;
            else if (type <= 10) k = 800;
            else if (type <= 40) k = rnd.next(1, 50);
            else k = rnd.next(51, 800);
        }
    }

    if (n < 1) n = 1;
    if (n > 1000000000000000000LL) n = 1000000000000000000LL;
    if (k < 1) k = 1;
    if (k > 800) k = 800;

    if (mode == "non") {

        long long interactor_seed = rnd.next(1LL, 1000000000000000000LL);
        cout << n << " " << k << " " << interactor_seed << endl;
    } else if (mode == "adp") {

        cout << n << " " << k << endl;
    } else {

        long long interactor_seed = rnd.next(1LL, 1000000000000000000LL);
        cout << n << " " << k << " " << interactor_seed << endl;
    }

    return 0;
}


This is an interactive problem!

Mr. 1048576 is one of those faculty who hates wasting his time in taking class attendance. Instead of taking attendance the old-fashioned way, he decided to try out something new today.

There are $n$ students in his class, having roll numbers $1$ to $n$. He knows that exactly $1$ student is absent today. In order to determine who is absent, he can ask some queries to the class. In each query, he can provide two integers $l$ and $r$ ($1\leq l\leq r\leq n$) and all students whose roll numbers are between $l$ and $r$ (inclusive) will raise their hands. He then counts them to determine if the roll number of the absent student lies between these values.

Things seemed fine until his teaching assistant noticed something — the students are dishonest! Some students whose roll numbers lie in the given range may not raise their hands, while some other students whose roll number does not lie in the given range may raise their hands. But the students don't want to raise much suspicion. So, only the following $4$ cases are possible for a particular query $(l,r)$ —

1. True Positive: $r-l+1$ students are present and $r-l+1$ students raised their hands.
2. True Negative: $r-l$ students are present and $r-l$ students raised their hands.
3. False Positive: $r-l$ students are present but $r-l+1$ students raised their hands.
4. False Negative: $r-l+1$ students are present but $r-l$ students raised their hands.

In the first two cases, the students are said to be answering honestly, while in the last two cases, the students are said to be answering dishonestly. The students can mutually decide upon their strategy, not known to Mr. 1048576. Also, the students do not want to raise any suspicion and at the same time, want to create a lot of confusion. So, their strategy always meets the following two conditions —

1. The students will never answer honestly $3$ times in a row.
2. The students will never answer dishonestly $3$ times in a row.

Mr. 1048576 is frustrated by this act of students. So, he is willing to mark at most $2$ students as absent (though he knows that only one is). The attendance is said to be successful if the student who is actually absent is among those two. Also, due to limited class time, he can only ask up to $\lceil\log_{1.116}{n}\rceil-1$ queries (weird numbers but okay). Help him complete a successful attendance.

Interaction

First read a line containing a single integer $t$ ($1\leq t\leq 2048$) denoting the number of independent test cases that you must solve.

For each test case, first read a line containing a single integer $n$ ($3\leq n\leq 10^5$). Then you may ask up to $\lceil\log_{1.116}{n}\rceil-1$ queries.

To ask a query, print a single line in the format "? l r" (without quotes) $(1\leq l\leq r\leq n)$. Then read a single line containing a single integer $x$ ($r-l\leq x\leq r-l+1$) denoting the number of students who raised their hands corresponding to the query.

To mark a student as absent, print a single line in the format "! a" (without quotes) $(1\leq a\leq n)$. Then read a single integer $y$ ($y\in\{0,1\}$). If the student with roll number $a$ was absent, $y=1$, else, $y=0$. Note that this operation does not count as a query but you can do this operation at most $2$ times.

To end a test case, print a single line in the format "#" (without quotes). Then you must continue solving the remaining test cases.

If you ask more queries than allowed or ask an invalid query, you will get the Wrong answer verdict.

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

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.

Note that the grader for this problem is adaptive meaning that the answer may change depending on your queries but will always remain consistent with the constraints and the answer to the previous queries.

Example

Input

```
2
5

3

2

1

2

0

1

0

2

0

1

6

6

2

2

0

1

1

0

0

0

1
```

Output

```
? 1 4

? 3 5

? 2 2

? 1 3

? 3 3

? 3 3

! 3

? 2 4

? 4 4

! 2

#

? 1 6

? 1 3

? 4 6

? 1 1

? 3 3

? 5 5

! 3

? 2 2

? 4 4

! 4

#
```

Note

For the first test case, the student with roll number $2$ is absent and the truth sequence is TFFTFTTF. During execution of your solution, this test case will use a non-adaptive grader.

For the second test case, the student with roll number $4$ is absent, and the truth sequence is FFTFTTFT. During the execution of your solution, in this test case your program will interact with an adaptive grader. So, the actual answer might be different depending on your queries but will always remain consistent with the responses to the previous queries.

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

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

static bool found = false;
static int guesses_used = 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 DeterministicGen {
    mt19937 rng;
    DeterministicGen(int seed) : rng(seed) {}
    int next(int low, int high) {
        return uniform_int_distribution<int>(low, high)(rng);
    }
};

void solve_test_case() {

    int n = inf.readInt();

    string mode = inf.readToken();

    int x;
    string s;

    if (mode == "fixed") {
        x = inf.readInt();
        s = inf.readToken();
    } else {

        DeterministicGen gen(n * 1337 + 7);
        x = gen.next(1, n);

        int len = 400;
        s = "";
        for (int i = 0; i < len; ++i) {
            vector<char> choices;

            bool canT = true;
            if (i >= 2 && s[i-1] == 'T' && s[i-2] == 'T') canT = false;

            bool canF = true;
            if (i >= 2 && s[i-1] == 'F' && s[i-2] == 'F') canF = false;

            if (canT) choices.push_back('T');
            if (canF) choices.push_back('F');

            s += choices[gen.next(0, choices.size() - 1)];
        }
    }

    double limit_val = ceil(log(n) / log(1.116)) - 1;
    long long limit = (long long)max(0.0, limit_val);
    query_limit += limit;

    log_metrics();

    cout << n << endl;

    found = false;
    guesses_used = 0;
    int query_idx = 0;

    while (true) {

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

        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (did not receive '#')");
        }

        if (token == "#") {
            if (!found) {
                finish(_wa, "Test case ended without identifying the absent student");
            }
            return;
        }

        if (token == "!") {
            int guess_a;
            if (!(cin >> guess_a)) finish(_pe, "Expected integer after '!'");

            guesses_used++;
            if (guesses_used > 2) {
                finish(_wa, "Too many guesses (>2)");
            }

            if (guess_a < 1 || guess_a > n) {
                finish(_wa, format("Invalid guess %d (n=%d)", guess_a, n));
            }

            int response = (guess_a == x ? 1 : 0);
            cout << response << endl;
            if (response == 1) found = true;
            continue;
        }

        int l, r;
        if (token == "?") {
            if (!(cin >> l >> r)) finish(_pe, "Expected l r after '?'");
        } else {

            try {
                l = stoi(token);
            } catch (...) {
                finish(_pe, "Expected integer l or command");
            }
            if (!(cin >> r)) finish(_pe, "Expected r");
        }

        queries++;

        if (l < 1 || r > n || l > r) {
            finish(_wa, format("Invalid query range [%d, %d] (n=%d)", l, r, n));
        }

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

        int actual_count;
        if (x >= l && x <= r) {

            actual_count = r - l;
        } else {

            actual_count = r - l + 1;
        }

        char truth = 'T';
        if (query_idx < (int)s.size()) {
            truth = s[query_idx];
        } else {

            truth = 'T';
        }
        query_idx++;

        int reply;
        if (truth == 'T') {
            reply = actual_count;
        } else {

            if (actual_count == r - l) reply = r - l + 1;
            else reply = r - l;
        }

        cout << reply << 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 cases passed");
    return 0;
}

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

using namespace std;

static long long total_queries = 0;
static long long total_limit = 0;
static bool interaction_failed = false;

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

    }
}

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

const int MASK_START = (1 << 4);
const int MASK_T1 = (1 << 0);
const int MASK_T2 = (1 << 1);
const int MASK_F1 = (1 << 2);
const int MASK_F2 = (1 << 3);

int next_mask_fn(int mask, char type) {
    int res = 0;
    if (type == 'T') {

        if (mask & MASK_START) res |= MASK_T1;
        if (mask & MASK_T1)    res |= MASK_T2;

        if (mask & MASK_F1)    res |= MASK_T1;
        if (mask & MASK_F2)    res |= MASK_T1;
    } else {

        if (mask & MASK_START) res |= MASK_F1;

        if (mask & MASK_T1)    res |= MASK_F1;
        if (mask & MASK_T2)    res |= MASK_F1;

        if (mask & MASK_F1)    res |= MASK_F2;

    }
    return res;
}

void solve_case() {

    int n = inf.readInt();
    string mode = inf.readToken();

    double limit_val = ceil(log((double)n) / log(1.116)) - 1.0;
    long long limit = max(0LL, (long long)limit_val);
    total_limit += limit;

    cout << n << endl;

    bool is_adaptive = (mode == "adaptive");
    int fixed_x = -1;
    string fixed_s = "";
    int fixed_idx = 0;

    if (!is_adaptive) {
        if (mode == "fixed") {
            fixed_x = inf.readInt();
            fixed_s = inf.readToken();
        } else {

            is_adaptive = true;
        }
    }

    vector<int> masks(n + 1, MASK_START);

    bool solved = false;

    log_metrics();

    while (true) {
        string type;
        if (!(cin >> type)) {
            finish(_pe, "Unexpected EOF while waiting for command");
        }

        if (type == "#") {

            break;
        }

        if (type == "!") {
            int a;
            cin >> a;
            if (a < 1 || a > n) finish(_wa, "Guess out of range");

            bool is_absent = false;

            if (!is_adaptive) {

                is_absent = (a == fixed_x);
            } else {

                bool can_be_other = false;
                for (int i = 1; i <= n; ++i) {
                    if (i != a && masks[i] != 0) {
                        can_be_other = true;
                        break;
                    }
                }

                if (can_be_other) {
                    is_absent = false;
                    masks[a] = 0;
                } else {

                    if (masks[a] != 0) {
                        is_absent = true;
                    } else {

                        is_absent = false;
                    }
                }
            }

            cout << (is_absent ? 1 : 0) << endl;
            if (is_absent) {
                solved = true;
            }

        } else if (type == "?") {
            int l, r;
            cin >> l >> r;
            if (l < 1 || r > n || l > r) finish(_wa, "Invalid query range");

            total_queries++;

            if (total_queries > 200000) finish(_pe, "Hard query limit exceeded");

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

            int ans = -1;

            if (!is_adaptive) {

                char truth = 'T';
                if (fixed_idx < (int)fixed_s.size()) {
                    truth = fixed_s[fixed_idx++];
                }

                bool in_range = (fixed_x >= l && fixed_x <= r);

                if (truth == 'T') {
                    ans = in_range ? (r - l + 1) : (r - l);
                } else {
                    ans = in_range ? (r - l) : (r - l + 1);
                }
            } else {

                int cnt_high = 0;
                int cnt_low = 0;

                for (int i = 1; i <= n; ++i) {
                    if (masks[i] == 0) continue;

                    bool in_range = (i >= l && i <= r);

                    char t_high = in_range ? 'T' : 'F';
                    if (next_mask_fn(masks[i], t_high)) cnt_high++;

                    char t_low = in_range ? 'F' : 'T';
                    if (next_mask_fn(masks[i], t_low)) cnt_low++;
                }

                if (cnt_high >= cnt_low) {
                    ans = r - l + 1;

                    for (int i = 1; i <= n; ++i) {
                        if (masks[i] == 0) continue;
                        bool in_range = (i >= l && i <= r);
                        masks[i] = next_mask_fn(masks[i], in_range ? 'T' : 'F');
                    }
                } else {
                    ans = r - l;

                    for (int i = 1; i <= n; ++i) {
                        if (masks[i] == 0) continue;
                        bool in_range = (i >= l && i <= r);
                        masks[i] = next_mask_fn(masks[i], in_range ? 'F' : 'T');
                    }
                }
            }
            cout << ans << endl;

        } else {
            finish(_wa, "Unknown command (expected '?', '!', or '#')");
        }
    }

    if (!solved) {
        interaction_failed = true;
    }
}

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

    if (interaction_failed) {
        finish(_wa, "Failed to solve one or more cases");
    } else {
        finish(_ok, "All cases solved");
    }

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

    if (n == -1) {
        int p = rnd.next(100);
        if (p < 5) {

            n = rnd.next(3, 10);
        } else if (p < 15) {

            n = rnd.next(11, 100);
        } else if (p < 30) {

            n = rnd.next(101, 1000);
        } else if (p < 50) {

            n = rnd.next(1001, 50000);
        } else if (p < 90) {

            n = rnd.next(90000, 99999);
        } else {

            n = 100000;
        }
    }

    cout << 1 << endl;

    if (mode == "non") {

        int x = rnd.next(1, n);

        int len = 300;
        string s = "";

        for (int i = 0; i < len; ++i) {
            vector<char> choices;

            bool canT = true;
            if (i >= 2 && s[i-1] == 'T' && s[i-2] == 'T') canT = false;

            bool canF = true;
            if (i >= 2 && s[i-1] == 'F' && s[i-2] == 'F') canF = false;

            if (canT) choices.push_back('T');
            if (canF) choices.push_back('F');

            s += choices[rnd.next(choices.size())];
        }

        cout << n << " fixed " << x << " " << s << endl;

    } else {

        cout << n << " adaptive" << endl;
    }

    return 0;
}


This is an interactive problem.

Kachina challenges you to guess her favorite binary string$^{\text{∗}}$ $s$ of length $n$. She defines $f(l, r)$ as the number of subsequences$^{\text{†}}$ of $\texttt{01}$ in $s_l s_{l+1} \ldots s_r$. Two subsequences are considered different if they are formed by deleting characters from different positions in the original string, even if the resulting subsequences consist of the same characters.

To determine $s$, you can ask her some questions. In each question, you can choose two indices $l$ and $r$ ($1 \leq l < r \leq n$) and ask her for the value of $f(l, r)$.

Determine and output $s$ after asking Kachina no more than $n$ questions. However, it may be the case that $s$ is impossible to be determined. In this case, you would need to report $\texttt{IMPOSSIBLE}$ instead.

Formally, $s$ is impossible to be determined if after asking $n$ questions, there are always multiple possible strings for $s$, regardless of what questions are asked. Note that if you report $\texttt{IMPOSSIBLE}$ when there exists a sequence of at most $n$ queries that will uniquely determine the binary string, you will get the Wrong Answer verdict.

$^{\text{∗}}$A binary string only contains characters $\texttt{0}$ and $\texttt{1}$.

$^{\text{†}}$A sequence $a$ is a subsequence of a sequence $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) elements. For example, subsequences of $\mathtt{1011101}$ are $\mathtt{0}$, $\mathtt{1}$, $\mathtt{11111}$, $\mathtt{0111}$, but not $\mathtt{000}$ nor $\mathtt{11100}$.

Input

The first line of input contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($2 \leq n \leq 10^4$) — the length of $s$.

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

Interaction

To ask a question, output a line in the following format (do not include quotes)

* "$\texttt{? l r}$" ($1 \leq l < r \leq n$)

The jury will return an integer $f(l, r)$.

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

* If $s$ is impossible to be determined, output "$\texttt{! IMPOSSIBLE}$"
* Otherwise, output "$\texttt{! s}$"

After that, proceed to process the next test case or terminate the program if it was the last test case. Printing the answer does not count as a query.

The interactor is not adaptive, meaning that the answer is known before the participant asks the queries and doesn't depend on the queries asked by the participant.

If your program makes more than $n$ queries for one test case, 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 printing a query do not forget to output the end of line and flush the output. Otherwise, you may get Idleness limit exceeded verdict. 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
5

4

0

1

2

2

0
```

Output

```
? 1 5

? 2 4

? 4 5

? 3 5

! 01001

? 1 2

! IMPOSSIBLE
```

Note

In the first test case:

In the first query, you ask Kachina for the value of $f(1, 5)$, and she responds with $4$ in the input stream.

In the second query, you ask Kachina for the value of $f(2, 4)$. Because there are no subsequences of $\texttt{01}$ in the string $\texttt{100}$, she responds with $0$ in the input stream.

After asking $4$ questions, you report $\texttt{01001}$ as $s$, and it is correct.

In the second test case:

In the first query, you ask Kachina for the value of $f(1, 2)$, and she responds with $0$ in the input stream. Notice that this is the only distinct question you can ask.

However, notice that the strings $00$ and $11$ both have an answer of $0$, and it is impossible to differentiate between the two. Therefore, we report IMPOSSIBLE.

Please note that this example only serves to demonstrate the interaction format. It is not guaranteed the queries provided are optimal or uniquely determine the answer. However, it can be shown there exists a sequence of at most $5$ queries that does uniquely determine sample test case $1$.

#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 parseNonNegLL(const string& s, long long& out) {
    if (s.empty()) return false;
    long long val = 0;
    for (char c : s) {
        if (c < '0' || c > '9') return false;
        int d = c - '0';
        if (val > (LLONG_MAX - d) / 10) return false;
        val = val * 10 + d;
    }
    out = val;
    return true;
}

struct TestData {
    int n = 0;
    string s;

    vector<long long> pref0, pref1, pref01;

    void build() {
        pref0.assign(n + 1, 0);
        pref1.assign(n + 1, 0);
        pref01.assign(n + 1, 0);
        for (int i = 1; i <= n; i++) {
            char c = s[i - 1];
            pref0[i] = pref0[i - 1] + (c == '0');
            pref1[i] = pref1[i - 1] + (c == '1');
            pref01[i] = pref01[i - 1] + (c == '1' ? pref0[i - 1] : 0);
        }
    }

    long long f(int l, int r) const {

        long long total = pref01[r] - pref01[l - 1];
        long long zerosBefore = pref0[l - 1];
        long long onesInRange = pref1[r] - pref1[l - 1];
        return total - zerosBefore * onesInRange;
    }

    bool impossible() const {
        return f(1, n) == 0;
    }
};

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

    int t = 0;
    try {
        t = inf.readInt();
    } catch (...) {
        query_limit = 0;
        log_metrics();
        finish(_pe, "Bad hidden input: missing t");
    }
    if (t < 1 || t > 1000000) {
        query_limit = 0;
        log_metrics();
        finish(_pe, "Bad hidden input: invalid t");
    }

    vector<TestData> tests;
    tests.reserve(t);

    long long sumN = 0;
    for (int tc = 0; tc < t; tc++) {
        TestData td;
        td.n = inf.readInt();
        if (td.n < 2 || td.n > 1000000) finish(_pe, "Bad hidden input: invalid n");
        string tok;
        try {
            tok = inf.readToken();
        } catch (...) {
            finish(_pe, "Bad hidden input: missing s");
        }
        if ((int)tok.size() != td.n) finish(_pe, "Bad hidden input: s length != n");
        for (char c : tok) if (c != '0' && c != '1') finish(_pe, "Bad hidden input: s not binary");
        td.s = tok;
        td.build();
        sumN += td.n;
        tests.push_back(std::move(td));
    }

    query_limit = sumN;
    log_metrics();

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

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

    for (int tc = 0; tc < t; tc++) {
        const TestData& td = tests[tc];
        cout << td.n << "\n";
        cout.flush();

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

            if (op == "?") {
                string sl, sr;
                if (!(cin >> sl >> sr)) finish(_pe, "Malformed query: missing l/r");

                long long ll = -1, rr = -1;
                if (!parseNonNegLL(sl, ll) || !parseNonNegLL(sr, rr)) finish(_pe, "Malformed query: l/r not integers");

                if (ll < 1 || rr < 1 || ll > td.n || rr > td.n || ll >= rr) finish(_pe, "Query indices out of range");

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

                long long ans = td.f((int)ll, (int)rr);
                cout << ans << "\n";
                cout.flush();
            } else if (op == "!") {
                string ans;
                if (!(cin >> ans)) finish(_pe, "Malformed answer: missing token");

                bool isImp = (ans == "IMPOSSIBLE");
                bool hiddenImp = td.impossible();

                if (isImp) {
                    if (!hiddenImp) finish(_wa, "Answered IMPOSSIBLE but solution exists");
                } else {
                    if ((int)ans.size() != td.n) finish(_wa, "Wrong length answer");
                    for (char c : ans) if (c != '0' && c != '1') finish(_pe, "Answer is not a binary string");
                    if (hiddenImp) finish(_wa, "Expected IMPOSSIBLE");
                    if (ans != td.s) finish(_wa, "Wrong string");
                }
                break;
            } else {
                finish(_pe, "Unknown operation (expected ? or !)");
            }
        }
    }

    finish(_ok, "OK");
}

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

static string buildImpossible(int n) {
    int onesPrefix = rnd.next(0, n);
    string s;
    s.append(onesPrefix, '1');
    s.append(n - onesPrefix, '0');
    return s;
}

static string buildHardSolvable(int n, long long seed) {
    if (n == 2) return "01";
    if (n == 3) return "001";

    int A = (int)(n * 45LL / 100LL) + rnd.next(0, max(1, n / 20));
    A = min(A, n - 2);

    int B = (int)(n * 45LL / 100LL) + rnd.next(0, max(1, n / 20));
    if (A + B + 1 > n) B = n - A - 1;
    if (B < 1) {
        B = 1;
        A = min(A, n - 2);
        if (A + B + 1 > n) A = max(0, n - B - 1);
    }

    string s;
    s.reserve(n);

    s.append(A, '1');
    s.append(B, '0');
    s.push_back('1');

    int remaining = n - (int)s.size();
    int curBit = 0;
    int blocks = 0;
    while (remaining > 0) {
        int cap = (blocks < 2 ? 80 : 18);
        int maxLen = min(remaining, cap);
        int len = rnd.next(1, maxLen);
        s.append(len, curBit ? '1' : '0');
        remaining -= len;
        blocks++;

        int p = rnd.next(0, 99);
        if (curBit == 0) {
            if (p < 35) curBit = 1;
        } else {
            if (p < 70) curBit = 0;
        }
    }

    int suf = min(n, 200);
    if (n >= 10) {
        int start = n - suf;
        char first = (seed & 1LL) ? '0' : '1';
        for (int i = start; i < n; i++) {
            s[i] = ((i - start) & 1) ? (first == '0' ? '1' : '0') : first;
        }

    }

    if ((int)s.size() != n) s.resize(n, '0');
    return s;
}

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

    string mode = opt<string>("mode", "non");
    int nArg = opt<int>("n", -1);
    int minn = opt<int>("minn", 2);
    int maxn = opt<int>("maxn", 10000);
    int impossibleArg = opt<int>("impossible", 0);

    ensuref(mode == "non" || mode == "adp", "Unknown --mode (expected non/adp)");
    ensuref(minn >= 2, "--minn must be >= 2");
    ensuref(maxn >= minn, "--maxn must be >= --minn");
    maxn = min(maxn, 10000);

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

    int n;
    if (seed == 1) n = 2;
    else if (seed == 2) n = 2;
    else if (seed == 3) n = 7;
    else {
        if (nArg != -1) n = nArg;
        else {
            int lo = max(minn, maxn - 2000);
            int hi = maxn;
            n = (seed % 13 == 0) ? maxn : rnd.next(lo, hi);
        }
    }
    n = max(n, 2);
    n = min(n, 10000);

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

    string s;
    if (seed == 1) {
        s = "01";
    } else if (seed == 2) {
        s = "00";
    } else if (seed == 3) {
        s = "1110001";
    } else {
        bool makeImpossible = (impossibleArg != 0) || (seed % 11 == 0);
        if (makeImpossible) s = buildImpossible(n);
        else s = buildHardSolvable(n, seed);
    }

    ensuref((int)s.size() == n, "Internal error: s.size()!=n");
    cout << n << "\n";
    cout << s << "\n";
    return 0;
}


This is an interactive problem.

You are the head coach of a chess club. The club has $2n$ players, each player has some strength which can be represented by a number, and all those numbers are distinct. The strengths of the players are not known to you.

You need to select $n$ players who would represent your club in the upcoming championship. Naturally, you want to select $n$ players with the highest strengths.

You can organize matches between the players to do that. In every match, you pick two players, they play some games, and you learn which one of the two has higher strength. You can wait for the outcome of a match before deciding who will participate in the next one.

However, you do not want to know exactly how those $n$ players compare between themselves, as that would make the championship itself less intriguing. More formally, you must reach a state where there is exactly one way to choose $n$ players with the highest strengths that is consistent with the outcomes of the matches you organized, but there must be at least two possible orderings of those $n$ players by strength that are consistent with the outcomes of the matches you organized.

Interaction

Your program has to process multiple test cases in one run. First, it should read the integer $t$ ($t \ge 1$) — the number of test cases. Then, it should process the test cases one by one.

In each test case, your program should start by reading the integer $n$ ($3 \le n \le 100$) — the number of players to select out of $2n$ players. The sum of squares of the values of $n$ over all test cases does not exceed $10\,000$.

Then your program can organize matches zero or more times. To organize a match, your program should print a match description formatted as ? $i$ $j$ — a question mark followed by two distinct numbers of players participating in the match. The players are numbered from 1 to $2n$, inclusive. Remember to flush the output after printing the match description. Then your program should read the match outcome — it will be either the greater-than character (>), if the first player in the match description has higher strength, or the less-than character (<), if the second player in the match description has higher strength.

Your program can organize at most $4n^2$ matches. After it is done organizing matches, it should print the exclamation mark (!) and continue to the next test case, or exit gracefully if this was the last test case. Remember to flush the output after printing the exclamation mark.

There must be exactly one way to choose $n$ players with the highest strength that is consistent with the outcomes of the matches you organized, but there must be at least two possible orderings of those $n$ players by their strength that are consistent with the outcomes of the matches you organized.

The judging program picks some distinct numbers as the strengths of all players before your program starts organizing matches and uses them to answer the requests.

Example

Input

```
2
3

>

<

>

<

>

>

3

<

<

<

>

>
```

Output

```
? 1 3

? 4 2

? 4 5

? 6 5

? 3 4

? 5 6

!

? 3 4

? 4 2

? 5 3

? 6 4

? 3 1

!
```

Note

In the example, the players in the first test case are sorted by strength in decreasing order. From the matches in the example output, we can deduce that players 1, 2, and 3 have the highest strength, but we do not know how the player 1 compares to the player 2.

#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 parsePosInt(const string& s, int& x) {
    if (s.empty()) return false;
    long long v = 0;
    for (char c : s) {
        if (c < '0' || c > '9') return false;
        v = v * 10 + (c - '0');
        if (v > INT_MAX) return false;
    }
    x = (int)v;
    return true;
}

struct TestCase {
    int n = 0;
    int m = 0;
    vector<int> rank;
};

static bool check_unique_top_and_ambiguous_order(int n, int m, vector< bitset<205> > g) {
    for (int k = 1; k <= m; ++k) {
        for (int i = 1; i <= m; ++i) {
            if (g[i].test(k)) g[i] |= g[k];
        }
        g[k].reset(k);
    }

    vector<int> outCnt(m + 1, 0), inCnt(m + 1, 0);
    for (int i = 1; i <= m; ++i) outCnt[i] = (int)g[i].count();
    for (int j = 1; j <= m; ++j) {
        int cnt = 0;
        for (int i = 1; i <= m; ++i) if (g[i].test(j)) ++cnt;
        inCnt[j] = cnt;
    }

    vector<int> top;
    top.reserve(n);
    vector<char> isTop(m + 1, 0);
    for (int i = 1; i <= m; ++i) {
        if (outCnt[i] >= n) {
            top.push_back(i);
            isTop[i] = 1;
        }
    }

    if ((int)top.size() != n) return false;

    for (int i = 1; i <= m; ++i) {
        if (!isTop[i]) {
            if (inCnt[i] < n) return false;
        }
    }

    bool ambiguous = false;
    for (int a = 0; a < n && !ambiguous; ++a) {
        for (int b = a + 1; b < n; ++b) {
            int u = top[a], v = top[b];
            if (!g[u].test(v) && !g[v].test(u)) {
                ambiguous = true;
                break;
            }
        }
    }
    return ambiguous;
}

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

    vector<TestCase> tests;
    int t = 0;
    try {
        t = inf.readInt();
        if (t < 1) finish(_pe, "Invalid hidden t");
        tests.resize(t);

        long long totalLimit = 0;
        for (int tc = 0; tc < t; ++tc) {
            int n = inf.readInt();
            if (n < 3 || n > 100) finish(_pe, "Invalid hidden n");
            int m = 2 * n;

            vector<int> p(m);
            for (int i = 0; i < m; ++i) p[i] = inf.readInt();

            vector<int> seen(m + 1, 0);
            for (int x : p) {
                if (x < 1 || x > m) finish(_pe, "Hidden permutation out of range");
                if (++seen[x] != 1) finish(_pe, "Hidden permutation has duplicates");
            }

            TestCase cs;
            cs.n = n;
            cs.m = m;
            cs.rank.assign(m + 1, -1);
            for (int i = 0; i < m; ++i) cs.rank[p[i]] = i;

            tests[tc] = std::move(cs);
            totalLimit += 4LL * n * n;
        }
        query_limit = totalLimit;
    } catch (const std::exception& e) {
        finish(_pe, string("Failed to read hidden input: ") + e.what());
    } catch (...) {
        finish(_pe, "Failed to read hidden input");
    }

    log_metrics();

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

    cout << t << endl;
    for (int tc = 0; tc < t; ++tc) {
        const int n = tests[tc].n;
        const int m = tests[tc].m;
        const vector<int>& rk = tests[tc].rank;

        cout << n << endl;

        vector< bitset<205> > g(m + 1);
        for (int i = 1; i <= m; ++i) g[i].reset();

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

            if (cmd == "!") {
                break;
            } else if (cmd == "?") {
                string si, sj;
                if (!(cin >> si >> sj)) finish(_pe, "Malformed query (missing indices)");

                int i = 0, j = 0;
                if (!parsePosInt(si, i) || !parsePosInt(sj, j)) finish(_pe, "Malformed query (non-integer indices)");
                if (i < 1 || i > m || j < 1 || j > m) finish(_pe, "Query index out of range");
                if (i == j) finish(_pe, "Query indices must be distinct");

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

                bool firstStronger = rk[i] < rk[j];
                if (firstStronger) {
                    g[i].set(j);
                    cout << ">" << endl;
                } else {
                    g[j].set(i);
                    cout << "<" << endl;
                }
            } else {
                finish(_pe, "Unknown command (expected '?' or '!')");
            }
        }

        if (!check_unique_top_and_ambiguous_order(n, m, g)) {
            finish(_wa, "State does not satisfy uniqueness/ambiguity requirements");
        }
    }

    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 Dinic {
    struct Edge {
        int to;
        int rev;
        long long cap;
    };
    int n;
    vector<vector<Edge>> g;
    vector<int> level;
    vector<int> it;

    explicit Dinic(int n_) : n(n_), g(n_), level(n_), it(n_) {}

    void addEdge(int fr, int to, long long cap) {
        Edge a{to, (int)g[to].size(), cap};
        Edge b{fr, (int)g[fr].size(), 0};
        g[fr].push_back(a);
        g[to].push_back(b);
    }

    bool bfs(int s, int t) {
        fill(level.begin(), level.end(), -1);
        queue<int> q;
        level[s] = 0;
        q.push(s);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (const auto& e : g[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
        return level[t] >= 0;
    }

    long long dfs(int v, int t, long long f) {
        if (v == t) return f;
        for (int& i = it[v]; i < (int)g[v].size(); i++) {
            Edge& e = g[v][i];
            if (e.cap <= 0 || level[e.to] != level[v] + 1) continue;
            long long ret = dfs(e.to, t, min(f, e.cap));
            if (ret > 0) {
                e.cap -= ret;
                g[e.to][e.rev].cap += ret;
                return ret;
            }
        }
        return 0;
    }

    long long maxflow(int s, int t) {
        long long flow = 0;
        while (bfs(s, t)) {
            fill(it.begin(), it.end(), 0);
            while (true) {
                long long pushed = dfs(s, t, (long long)4e18);
                if (pushed == 0) break;
                flow += pushed;
            }
        }
        return flow;
    }
};

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

static const int MAXM = 205;

static long long deltaIfAdd(int m, const vector<bitset<MAXM>>& reach, int u, int v) {
    bitset<MAXM> add = reach[v];
    add.set(v);
    long long delta = 0;
    for (int x = 1; x <= m; x++) {
        if (x == u || reach[x].test(u)) {
            bitset<MAXM> newly = add & (~reach[x]);
            delta += (long long)newly.count();
        }
    }
    return delta;
}

static void addEdgeTransitive(int m, vector<bitset<MAXM>>& reach, int u, int v) {
    bitset<MAXM> add = reach[v];
    add.set(v);
    for (int x = 1; x <= m; x++) {
        if (x == u || reach[x].test(u)) {
            reach[x] |= add;
        }
    }
}

static long long maxIdealSizeExcludingForbidden(
    int m,
    const bitset<MAXM>& forbidden,
    const vector<pair<int,int>>& closureEdges
) {
    const long long PEN = 1000000LL;
    int S = 0;
    int T = m + 1;
    Dinic dinic(m + 2);

    long long totalPos = 0;
    for (int v = 1; v <= m; v++) {
        if (forbidden.test(v)) {
            dinic.addEdge(v, T, PEN);
        } else {
            dinic.addEdge(S, v, 1);
            totalPos++;
        }
    }
    for (auto [a, b] : closureEdges) {
        if (a == b) continue;
        dinic.addEdge(a, b, PEN);
    }

    long long mincut = dinic.maxflow(S, T);
    long long maxWeight = totalPos - mincut;
    if (maxWeight < 0) maxWeight = 0;
    if (maxWeight > totalPos) maxWeight = totalPos;
    return maxWeight;
}

static bool checkFinishedState(
    int n,
    int m,
    const vector<bitset<MAXM>>& reach,
    const vector<pair<int,int>>& closureEdges
) {
    vector<int> alwaysIn;
    alwaysIn.reserve(m);
    for (int v = 1; v <= m; v++) {
        bitset<MAXM> forbidden = reach[v];
        forbidden.set(v);
        long long maxBefore = maxIdealSizeExcludingForbidden(m, forbidden, closureEdges);
        if (maxBefore <= n - 1) alwaysIn.push_back(v);
    }

    if ((int)alwaysIn.size() != n) return false;

    bool hasIncomparable = false;
    for (int i = 0; i < n && !hasIncomparable; i++) {
        for (int j = i + 1; j < n; j++) {
            int a = alwaysIn[i], b = alwaysIn[j];
            if (!reach[a].test(b) && !reach[b].test(a)) {
                hasIncomparable = true;
                break;
            }
        }
    }
    return hasIncomparable;
}

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

    int t = inf.readInt(1, 100000, "t");
    vector<int> ns(t);
    for (int tc = 0; tc < t; tc++) {
        ns[tc] = inf.readInt(3, 100, "n");
        query_limit += 4LL * ns[tc] * ns[tc];
    }

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

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

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

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

        bool fixedInstance = false;
        vector<int> posIndex(m + 1, -1);

        if (t == 1 && tc == 0 && !inf.seekEof()) {
            vector<int> p(m);
            vector<int> seen(m + 1, 0);
            for (int i = 0; i < m; i++) {
                int x = inf.readInt(1, m, "perm_i");
                if (++seen[x] != 1) finish(_pe, "invalid permutation in input");
                p[i] = x;
            }
            for (int i = 0; i < m; i++) posIndex[p[i]] = i;
            fixedInstance = true;
        }

        vector<bitset<MAXM>> reach(m + 1);
        vector<vector<unsigned char>> direct(m + 1, vector<unsigned char>(m + 1, 0));
        vector<pair<int,int>> closureEdges;
        closureEdges.reserve(4 * n * n);

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

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

            if (cmd == "!") {
                break;
            }
            if (cmd != "?") finish(_pe, "invalid command token");

            string si, sj;
            if (!(cin >> si >> sj)) finish(_pe, "malformed query");
            int i, j;
            if (!parsePosInt(si, i) || !parsePosInt(sj, j)) finish(_pe, "non-integer query indices");
            if (i < 1 || i > m || j < 1 || j > m || i == j) finish(_pe, "query indices out of range");

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

            bool iStronger;
            if (fixedInstance) {
                if (posIndex[i] < 0 || posIndex[j] < 0) finish(_pe, "internal: missing posIndex");
                iStronger = (posIndex[i] < posIndex[j]);
            } else {
                if (reach[i].test(j)) {
                    iStronger = true;
                } else if (reach[j].test(i)) {
                    iStronger = false;
                } else {
                    long long d1 = deltaIfAdd(m, reach, i, j);
                    long long d2 = deltaIfAdd(m, reach, j, i);
                    if (d1 != d2) iStronger = (d1 < d2);
                    else iStronger = (i < j);
                }
            }

            int u = iStronger ? i : j;
            int v = iStronger ? j : i;

            if (reach[v].test(u)) finish(_pe, "internal: contradiction/cycle detected");

            if (!reach[u].test(v)) {
                if (!direct[u][v]) {
                    direct[u][v] = 1;
                    closureEdges.push_back({v, u});
                }
                addEdgeTransitive(m, reach, u, v);
            }

            cout << (iStronger ? ">" : "<") << "\n";
            cout.flush();
        }

        if (!checkFinishedState(n, m, reach, closureEdges)) {
            finish(_wa, "conditions not satisfied at '!'");
        }
    }

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

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

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

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

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

    int n = forcedN;
    if (n == -1) {
        if (mode == "adp") {
            if (seed == 1) n = 3;
            else if (seed == 2) n = 100;
            else if (seed == 3) n = 100;
            else n = rnd.next(90, 100);
        } else {
            if (seed == 1) n = 3;
            else if (seed == 2) n = 100;
            else if (seed == 3) n = 50;
            else {
                int roll = rnd.next(1, 10);
                if (roll == 1) n = rnd.next(3, 10);
                else n = rnd.next(80, 100);
            }
        }
    }

    n = max(3, min(100, n));
    int m = 2 * n;

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

    if (mode == "adp") {
        return 0;
    }

    vector<int> p;
    p.reserve(m);

    if (seed == 1) {

        p = {1, 3, 5, 6, 4, 2};
    } else if (seed == 2) {

        for (int x = m - 1; x >= 1; x -= 2) p.push_back(x);
        for (int x = 2; x <= m; x += 2) p.push_back(x);
    } else if (seed == 3) {

        vector<int> top, bot;
        for (int i = 1; i <= m; ++i) {
            if (i % 2 == 0) top.push_back(i);
            else bot.push_back(i);
        }

        int L = 0, R = (int)top.size() - 1;
        while (L <= R) {
            p.push_back(top[R--]);
            if (L <= R) p.push_back(top[L++]);
        }

        L = 0; R = (int)bot.size() - 1;
        while (L <= R) {
            p.push_back(bot[L++]);
            if (L <= R) p.push_back(bot[R--]);
        }
    } else {

        vector<int> topPlayers, bottomPlayers;
        topPlayers.reserve(n);
        bottomPlayers.reserve(n);

        for (int k = 1; k <= n; ++k) {
            int a = 2 * k - 1;
            int b = 2 * k;
            if (rnd.next(0, 1) == 0) {
                topPlayers.push_back(a);
                bottomPlayers.push_back(b);
            } else {
                topPlayers.push_back(b);
                bottomPlayers.push_back(a);
            }
        }

        shuffleVec(topPlayers);
        shuffleVec(bottomPlayers);

        vector<int> topRiffled;
        topRiffled.reserve(n);
        {
            vector<int> tmp = topPlayers;
            sort(tmp.begin(), tmp.end());
            int L = 0, R = (int)tmp.size() - 1;
            while (L <= R) {
                topRiffled.push_back(tmp[R--]);
                if (L <= R) topRiffled.push_back(tmp[L++]);
            }

            int shift = rnd.next(0, (int)topRiffled.size() - 1);
            rotate(topRiffled.begin(), topRiffled.begin() + shift, topRiffled.end());
        }

        vector<int> bottomRiffled;
        bottomRiffled.reserve(n);
        {
            vector<int> tmp = bottomPlayers;
            sort(tmp.begin(), tmp.end());
            int L = 0, R = (int)tmp.size() - 1;
            while (L <= R) {
                bottomRiffled.push_back(tmp[L++]);
                if (L <= R) bottomRiffled.push_back(tmp[R--]);
            }
            int shift = rnd.next(0, (int)bottomRiffled.size() - 1);
            rotate(bottomRiffled.begin(), bottomRiffled.begin() + shift, bottomRiffled.end());
        }

        for (int x : topRiffled) p.push_back(x);
        for (int x : bottomRiffled) p.push_back(x);
    }

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


This is an interactive problem.

Note: the XOR-sum of an array $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) is defined as $a_1 \oplus a_2 \oplus \ldots \oplus a_n$, where $\oplus$ denotes the bitwise XOR operation.

Little Dormi received an array of $n$ integers $a_1, a_2, \ldots, a_n$ for Christmas. However, while playing with it over the winter break, he accidentally dropped it into his XOR machine, and the array got lost.

The XOR machine is currently configured with a query size of $k$ (which you cannot change), and allows you to perform the following type of query: by giving the machine $k$ distinct indices $x_1, x_2, \ldots, x_k$, it will output $a_{x_1} \oplus a_{x_2} \oplus \ldots \oplus a_{x_k}$.

As Little Dormi's older brother, you would like to help him recover the XOR-sum of his array $a_1, a_2, \ldots, a_n$ by querying the XOR machine.

Little Dormi isn't very patient, so to be as fast as possible, you must query the XOR machine the minimum number of times to find the XOR-sum of his array. Formally, let $d$ be the minimum number of queries needed to find the XOR-sum of any array of length $n$ with a query size of $k$. Your program will be accepted if you find the correct XOR-sum in at most $d$ queries.

Lastly, you also noticed that with certain configurations of the machine $k$ and values of $n$, it may not be possible to recover the XOR-sum of Little Dormi's lost array. If that is the case, you should report it as well.

The array $a_1, a_2, \ldots, a_n$ is fixed before you start querying the XOR machine and does not change with the queries.

Input

The only line of input contains the integers $n$ and $k$ ($1 \le n \le 500$, $1 \le k \le n$), the length of the lost array and the configured query size of the XOR machine.

Elements of the original array satisfy $1 \le a_i \le 10^9$.

It can be proven that that if it is possible to recover the XOR sum under the given constraints, it can be done in at most $500$ queries. That is, $d \le 500$.

After taking $n$ and $k$, begin interaction.

Output

If it is impossible to recover the XOR-sum of the array, output $-1$ immediately after taking $n$ and $k$. Do not begin interaction.

Otherwise, when your program finds the XOR-sum of the lost array $a_1, a_2, \ldots, a_n$, report the answer in the following format: "! x", where $x$ is the XOR sum of the array $a_1, a_2, \ldots, a_n$, and terminate your program normally immediately after flushing the output stream.

Note that answering does not count as a query.

Interaction

Each query is made in the format "? b", where $b$ is an array of exactly $k$ distinct integers from $1$ to $n$ denoting the indices of the elements in the lost array that you want to query the XOR sum of.

You will then receive an integer $x$, the XOR sum of the queried elements. It can be proven that $0 \le x \le 2 \cdot 10^9$ will always be true.

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 $500$ queries (which is the hard limit), the interaction will terminate immediately and give you a Wrong Answer verdict. Note that if you exceed $d$ queries, the interaction will continue normally unless you also exceed the $500$ query hard limit, though you will still receive a Wrong Answer verdict either way.

Examples

Input

```
5 3

4

0

1
```

Output

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

Input

```
3 2
```

Output

```
-1
```

Note

In the first example interaction, the array $a_1, a_2, \ldots, a_n$ is $2, 1, 7, 5, 6$ and its XOR-sum is $7$.

The first query made asks for indices $1,2,3$, so the response is $a_1 \oplus a_2 \oplus a_3 = 2 \oplus 1 \oplus 7 = 4$.

The second query made asks for indices $2,3,5$, so the response is $a_2 \oplus a_3 \oplus a_5 = 1 \oplus 7 \oplus 6 = 0$.

The third query made asks for indices $4,1,5$, so the response is $a_4 \oplus a_1 \oplus a_5 = 5 \oplus 2 \oplus 6 = 1$. Note that the indices may be output in any order.

Additionally, even though three queries were made in the example interaction, it is just meant to demonstrate the interaction format and does not necessarily represent an optimal strategy.

In the second example interaction, there is no way to recover the XOR-sum of Little Dormi's array no matter what is queried, so the program immediately outputs $-1$ and exits.

#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 int compute_min_queries(int n, int k) {
    const int INF = 1e9;
    vector<int> dist(n + 1, INF);
    queue<int> q;
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        int d = dist[cur];
        int max_take_from_ones = min(cur, k);
        for (int take_from_ones = 0; take_from_ones <= max_take_from_ones; ++take_from_ones) {
            int take_from_zeros = k - take_from_ones;
            if (take_from_zeros > n - cur) continue;
            int nxt = cur + k - 2 * take_from_ones;
            if (nxt < 0 || nxt > n) continue;
            if (dist[nxt] > d + 1) {
                dist[nxt] = d + 1;
                q.push(nxt);
            }
        }
    }
    return dist[n] >= INF ? -1 : dist[n];
}

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

static bool read_long_long(long long& out) {
    return static_cast<bool>(cin >> out);
}

static bool parse_long_long_token(const string& token, long long& value) {
    try {
        size_t idx = 0;
        long long v = stoll(token, &idx, 10);
        if (idx != token.size()) return false;
        value = v;
        return true;
    } catch (...) {
        return false;
    }
}

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

    const int n = inf.readInt(1, 500, "n");
    const int k = inf.readInt(1, n, "k");
    vector<int> a(n + 1, 0);
    int xorsum = 0;
    for (int i = 1; i <= n; i++) {
        a[i] = inf.readInt(1, 1000000000, "a[i]");
        xorsum ^= a[i];
    }
    if (!inf.seekEof()) finish(_fail, "Unexpected extra tokens in input");

    const bool solvable = (k % 2 == 1) || (n % 2 == 0);
    const int d = solvable ? compute_min_queries(n, k) : -1;
    if (solvable && (d < 0 || d > 500)) finish(_fail, "Internal: invalid d computed");
    query_limit = solvable ? d : 0;
    const long long hard_limit = 500;

    log_metrics();

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

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

        if (!tok.empty() && tok[0] == '?') {
            if (!solvable) {
                send_minus_one();
                finish(_wa, "Queries are not allowed when the instance is impossible");
            }

            vector<int> idxs(k);
            for (int i = 0; i < k; i++) {
                long long v = 0;
                if (!read_long_long(v)) {
                    send_minus_one();
                    finish(_pe, "Malformed query: expected k indices");
                }
                idxs[i] = (int)v;
            }
            queries++;
            if (queries > hard_limit) {
                send_minus_one();
                finish(_wa, "Query hard limit exceeded (500)");
            }
            vector<char> seen(n + 1, 0);
            int res = 0;
            for (int pos = 0; pos < k; pos++) {
                int id = idxs[pos];
                if (id < 1 || id > n) {
                    send_minus_one();
                    finish(_wa, "Query index out of range");
                }
                if (seen[id]) {
                    send_minus_one();
                    finish(_wa, "Query indices must be distinct");
                }
                seen[id] = 1;
                res ^= a[id];
            }
            cout << res << "\n";
            cout.flush();
            continue;
        }

        long long answer = 0;
        if (tok == "-1") {
            answer = -1;
        } else if (!tok.empty() && tok[0] == '!') {
            if (tok.size() == 1) {
                if (!read_long_long(answer)) finish(_pe, "Malformed final answer: expected integer after '!'");
            } else {
                if (!parse_long_long_token(tok.substr(1), answer)) {
                    finish(_pe, "Malformed final answer token");
                }
            }
        } else {
            finish(_pe, "Unknown operation token (expected '?' or '!')");
        }

        if (answer == -1) {
            if (solvable) finish(_wa, "Reported -1 but the instance is solvable");
            finish(_ok, "Correctly reported impossible");
        }
        if (!solvable) finish(_wa, "Instance is impossible but contestant did not output -1");
        if ((int)answer != xorsum) finish(_wa, "Wrong XOR-sum");

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

static uint64_t fnv1a64(const string& s) {
    uint64_t h = 14695981039346656037ULL;
    for (unsigned char c : s) {
        h ^= (uint64_t)c;
        h *= 1099511628211ULL;
    }
    return h;
}

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

static int compute_min_queries(int n, int k) {
    const int INF = 1e9;
    vector<int> dist(n + 1, INF);
    queue<int> q;
    dist[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        int d = dist[cur];
        int max_take_from_ones = min(cur, k);
        for (int take_from_ones = 0; take_from_ones <= max_take_from_ones; ++take_from_ones) {
            int take_from_zeros = k - take_from_ones;
            if (take_from_zeros > n - cur) continue;
            int nxt = cur + k - 2 * take_from_ones;
            if (nxt < 0 || nxt > n) continue;
            if (dist[nxt] > d + 1) {
                dist[nxt] = d + 1;
                q.push(nxt);
            }
        }
    }
    return dist[n] >= INF ? -1 : dist[n];
}

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

static bool read_long_long(long long& out) {
    return static_cast<bool>(cin >> out);
}

static bool parse_long_long_token(const string& token, long long& value) {
    try {
        size_t idx = 0;
        long long v = stoll(token, &idx, 10);
        if (idx != token.size()) return false;
        value = v;
        return true;
    } catch (...) {
        return false;
    }
}

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

    const int n = inf.readInt(1, 500, "n");
    const int k = inf.readInt(1, n, "k");
    if (!inf.seekEof()) finish(_fail, "Unexpected extra tokens in adaptive input");

    const bool solvable = (k % 2 == 1) || (n % 2 == 0);
    const int d = solvable ? compute_min_queries(n, k) : -1;
    if (solvable && (d < 0 || d > 500)) finish(_fail, "Internal: invalid d computed");
    query_limit = solvable ? d : 0;
    const long long hard_limit = 500;

    uint64_t seed = fnv1a64((argc >= 2) ? string(argv[1]) : string("cf1534E"));
    seed ^= (uint64_t)n * 0x9e3779b97f4a7c15ULL;
    seed ^= (uint64_t)k * 0xbf58476d1ce4e5b9ULL;
    vector<int> a(n + 1, 0);
    int xorsum = 0;
    for (int i = 1; i <= n; i++) {
        int v = (int)(splitmix64(seed) % 1000000000ULL) + 1;
        a[i] = v;
        xorsum ^= v;
    }

    log_metrics();

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

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

        if (!tok.empty() && tok[0] == '?') {
            if (!solvable) {
                send_minus_one();
                finish(_wa, "Queries are not allowed when the instance is impossible");
            }

            vector<int> idxs(k);
            for (int i = 0; i < k; i++) {
                long long v = 0;
                if (!read_long_long(v)) {
                    send_minus_one();
                    finish(_pe, "Malformed query: expected k indices");
                }
                idxs[i] = (int)v;
            }
            queries++;
            if (queries > hard_limit) {
                send_minus_one();
                finish(_wa, "Query hard limit exceeded (500)");
            }
            vector<char> seen(n + 1, 0);
            int res = 0;
            for (int pos = 0; pos < k; pos++) {
                int id = idxs[pos];
                if (id < 1 || id > n) {
                    send_minus_one();
                    finish(_wa, "Query index out of range");
                }
                if (seen[id]) {
                    send_minus_one();
                    finish(_wa, "Query indices must be distinct");
                }
                seen[id] = 1;
                res ^= a[id];
            }
            cout << res << "\n";
            cout.flush();
            continue;
        }

        long long answer = 0;
        if (tok == "-1") {
            answer = -1;
        } else if (!tok.empty() && tok[0] == '!') {
            if (tok.size() == 1) {
                if (!read_long_long(answer)) finish(_pe, "Malformed final answer: expected integer after '!'");
            } else {
                if (!parse_long_long_token(tok.substr(1), answer)) {
                    finish(_pe, "Malformed final answer token");
                }
            }
        } else {
            finish(_pe, "Unknown operation token (expected '?' or '!')");
        }

        if (answer == -1) {
            if (solvable) finish(_wa, "Reported -1 but the instance is solvable");
            finish(_ok, "Correctly reported impossible");
        }
        if (!solvable) finish(_wa, "Instance is impossible but contestant did not output -1");
        if ((int)answer != xorsum) finish(_wa, "Wrong XOR-sum");

        finish(_ok, "OK");
    }
}

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

static long long readSeed(int argc, char* argv[]) {
    if (argc <= 1) return 1;
    string s = argv[1];

    long long x = 1;
    try {
        x = stoll(s);
    } catch (...) {
        x = 1;
    }
    return x;
}

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 vector<int> genArray(int n, long long seed) {
    vector<int> a(n + 1, 1);

    if (n == 1) {
        a[1] = (seed == 1 ? 1000000000 : rnd.next(1, 1000000000));
        return a;
    }

    vector<int> base = {
        1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
        127, 255, 1023, 4095, 65535,
        (int)((1LL << 28) - 1), (int)(1LL << 28),
        (int)((1LL << 29) - 1), (int)(1LL << 29),
        123456789, 234567891, 345678912, 456789123,
        424242424, 700000000, 777777777, 900000001,
        987654321, 999999937, 1000000000
    };

    shuffleVec(base);

    int m = min(n, (int)base.size());
    for (int i = 1; i <= m; ++i) a[i] = base[i - 1];

    for (int i = m + 1; i <= n; ++i) {
        int t = rnd.next(1, 100);
        if (t <= 8) a[i] = 1000000000;
        else if (t <= 16) a[i] = 1;
        else a[i] = rnd.next(1, 1000000000);
    }

    for (int i = 1; i <= n; ++i) {
        if (a[i] < 1) a[i] = 1;
        if (a[i] > 1000000000) a[i] = 1000000000;
    }
    return a;
}

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

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

    ensuref(mode == "non" || mode == "adp", "mode must be 'non' or 'adp'");

    long long seed = readSeed(argc, argv);

    int n = -1, k = -1;

    if (forcedN != -1 || forcedK != -1) {
        if (forcedN == -1) forcedN = min(500, max(1, forcedK));
        if (forcedK == -1) forcedK = min(forcedN, max(1, forcedN - 1));
        n = forcedN;
        k = forcedK;
    } else {
        if (seed == 1) {
            n = 1; k = 1;
        } else if (seed == 2) {
            n = 3; k = 2;
        } else if (seed == 3) {
            n = 500; k = 499;
        } else {
            int pick = rnd.next(1, 100);
            if (pick <= 65) {
                n = 500; k = 499;
            } else if (pick <= 80) {
                n = rnd.next(470, 500);
                if (n % 2 == 1) --n;
                if (n < 2) n = 2;
                k = n - 1;
            } else if (pick <= 90) {
                n = rnd.next(3, 499);
                if (n % 2 == 0) ++n;
                if (n > 499) n = 499;
                k = rnd.next(2, n);
                if (k % 2 == 1) ++k;
                if (k > n) --k;
                if (k < 2) k = 2;

            } else {
                n = 500; k = 1;
            }
        }
    }

    ensuref(1 <= n && n <= 500, "n out of range");
    ensuref(1 <= k && k <= n, "k out of range");

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

    vector<int> a = genArray(n, seed);
    cout << n << " " << k << "\n";
    for (int i = 1; i <= n; ++i) {
        if (i > 1) cout << ' ';
        cout << a[i];
    }
    cout << "\n";
    return 0;
}


All problems in this contest share the same statement, the only difference is the test your solution runs on. For further information on scoring please refer to "Scoring" section of the statement.

This is an interactive problem.

Imagine you are a treasure hunter, a very skillful one. One day you came across an ancient map which could help you to become rich. The map shows multiple forestry roads, and at each junction there is a treasure. So, you start your journey hoping to retrieve all the hidden treasures, but you don't know yet that there is a wicked wizard standing against you and craving to tangle up these roads and impede your achievements.

The treasure map is represented as an undirected graph in which vertices correspond to junctions and edges correspond to roads. Your path begins at a certain fixed vertex with a label known to you. Every time you come to a vertex that you have not been to before, you dig up a treasure chest and put a flag in this vertex. At the initial vertex you'll find a treasure chest immediately and, consequently, you'll put a flag there immediately as well.

When you are standing at the junction you can see for each of the adjacent vertices its degree and if there is a flag there. There are no other things you can see from there. Besides, the power of the wicked wizard is so great that he is able to change the location of the roads and junctions on the map without changing the graph structure. Therefore, the sequence of the roads coming from the junction $v$ might be different each time you come in the junction $v$. However, keep in mind that the set of adjacent crossroads does not change, and you are well aware of previously dug treasures at each adjacent to $v$ vertex.

Your goal is to collect treasures from all vertices of the graph as fast as you can. Good luck in hunting!

Interaction

On the first line the interactor prints an integer $t$ ($1 \leq t \leq 5$) — the number of maps for which you need to solve the problem.

Then for each of the $t$ maps interactor firstly prints the graph description and after that interaction on this map starts. The map description is given in the following format.

The first line contains four integers $n, m, start, base\_move\_count$ ($2 \leq n \leq 300$, $1 \leq m \leq min(\frac{n(n-1)}{2}, 25n)$, $1 \leq start \leq n$, $1000 \leq base\_move\_count \leq 30000$) — the number of vertices and edges in the graph, the label of the vertex where you start the journey and some base move count, on which the score for the map depends. It's guaranteed that the jury has a solution traversing the map using not more than $base\_move\_count$ moves with high probability.

The next $m$ lines contain descriptions of the edges of the graph $u, v$ ($1 \leq u, v \leq n$, $u \neq v$). It is guaranteed that the graph is connected, does not contain multiple edges and the degrees of all vertices do not exceed 50.

You can find map descriptions for all tests in the archive 'map\_descriptions.zip' which you can find in any of the archives 'problem-X-materials.zip' in the section "Contest materials" — they are all the same.

After that the interaction begins. The interactor prints vertex descriptions in the following format:

R~d~deg\_1~flag\_1~deg\_2~flag\_2 \ldots deg\_d~flag\_d, where $d$ is the degree of the current vertex, $deg_i$ is the degree of the $i$-th vertex adjacent to the current one, and $flag_i$ (0 or 1) is an indicator if the $i$-th adjacent vertex contains a flag. The order of neighbors in the vertex description is chosen by the interactor uniformly at random independently each time. Please keep in mind that you are not given the actual labels of adajacent vertices.

In response to the description of the vertex you should print a single integer $i$ ($1 \leq i \leq d$), which means that you have chosen the vertex with description $deg_i~flag_i$. Remember to use the flush operation after each output. If your output is invalid, you will get a "Wrong Answer" verdict.

When you have visited all the vertices of the graph at least once, the interactor prints the string "AC" instead of the vertex description. If you use more than $2 \cdot base\_move\_count$ moves, the interactor prints the string "F". In both cases, you have to either start reading the description of the next map, or terminate the program, if it has been the last map in the test.

Below the example of interaction is presented. Note that the test from the example is not the same that your solution will be tested on.

```
|  |  |
| --- | --- |
| Interactor | Solution |
| 1 |  |
| 3 3 1 1000 |  |
| 1 2 |  |
| 2 3 |  |
| 3 1 |  |
| R 2 2 0 2 0 |  |
|  | 1 |
| R 2 2 0 2 1 |  |
|  | 2 |
| R 2 2 0 2 1 |  |
|  | 1 |
| AC |  |
```

Scoring

All problems of this contest share the same statement and differ only in the test. Each problem contains one test. Map descriptions for the test are available to look at in the archive.

Each test consists of several maps.

The solution score for the problem will be $0$ in case your solution for some map failed to get an answer "AC" or "F". If the solution correctly interacted with the interactor on all $t$ maps, the score for the task will be equal to the sum of the scores for each of the maps.

If you have successfully passed all vertices of a graph with $n$ vertices using $moves$ moves, the score for the map is calculated as follows. Denote

base\\_fraction=\frac{base\\_move\\_count + 1}{n},sol\\_fraction=\frac{moves+1}{n},c=\frac{90}{\sqrt{base\\_fraction - 1}}.

Then:

* if $moves \leq base\_move\_count$, you get $100-c \sqrt{sol\_fraction - 1}$ points.
* if $base\_move\_count < moves \leq 2 \cdot base\_move\_count$, you get $20 - \frac{10\cdot(moves + 1)}{base\_move\_count + 1}$ points.

If you use more than $2 \cdot base\_move\_count$ moves, you get 0 points for the map.

For each problem the solution with the highest score is chosen. Please note that the maximum is chosen for the entire test as a whole, not for each separate map.

The final result of the participant is the sum of points for each of the problems.

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

using namespace std;

static long long queries = 0;
static long long query_limit = 0;
static mt19937 rng(42);

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 read_choice_index() {
    string token;
    if (!(cin >> token)) {
        finish(_wa, "Unexpected EOF while reading move");
    }
    if (token.empty()) {
        finish(_wa, "Invalid move token");
    }
    for (char ch : token) {
        if (ch < '0' || ch > '9') {
            finish(_wa, "Invalid move token");
        }
    }
    try {
        size_t pos = 0;
        long long v = stoll(token, &pos);
        if (pos != token.size() || v > numeric_limits<int>::max()) {
            finish(_wa, "Invalid move token");
        }
        return (int)v;
    } catch (...) {
        finish(_wa, "Invalid move token");
    }
    return -1;
}

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, 5, "t");
    cout << t << endl;
    cout.flush();

    for (int tc = 0; tc < t; ++tc) {
        int n = inf.readInt(2, 300, "n");
        int max_m = (int)min(1LL * n * (n - 1) / 2, 25LL * n);
        int m = inf.readInt(1, max_m, "m");
        int start = inf.readInt(1, n, "start");
        int base_move_count = inf.readInt(1000, 30000, "base_move_count");

        long long map_limit = 2LL * base_move_count;
        query_limit += map_limit;
        if (tc == 0) log_metrics();

        vector<vector<int>> adj(n + 1);
        vector<int> deg(n + 1, 0);
        vector<pair<int, int>> edges;
        edges.reserve(m);

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

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

        vector<char> visited(n + 1, 0);
        visited[start] = 1;
        int visited_count = 1;
        int cur = start;
        long long moves = 0;

        while (true) {
            if (visited_count == n) {
                cout << "AC" << endl;
                cout.flush();
                break;
            }
            if (moves > map_limit) {
                cout << "F" << endl;
                cout.flush();
                break;
            }

            vector<int> neighbors = adj[cur];
            shuffle(neighbors.begin(), neighbors.end(), rng);

            cout << "R " << neighbors.size();
            for (int v : neighbors) {
                cout << " " << deg[v] << " " << (visited[v] ? 1 : 0);
            }
            cout << endl;
            cout.flush();

            int choice = read_choice_index();
            if (choice < 1 || choice > (int)neighbors.size()) {
                finish(_wa, format("Invalid choice %d (expected 1..%d)", choice, (int)neighbors.size()));
            }

            cur = neighbors[choice - 1];
            moves++;
            queries++;
            if (queries % 200 == 0) log_metrics();

            if (!visited[cur]) {
                visited[cur] = 1;
                visited_count++;
            }
        }
    }

    finish(_ok, "All maps processed");
    return 0;
}

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

using namespace std;

struct DSU {
    vector<int> p;
    DSU(int n) {
        p.resize(n + 1);
        iota(p.begin(), p.end(), 0);
    }
    int find(int x) {
        return (x == p[x]) ? x : (p[x] = find(p[x]));
    }
    bool unite(int x, int y) {
        int rx = find(x), ry = find(y);
        if (rx != ry) {
            p[rx] = ry;
            return true;
        }
        return false;
    }
};

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

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

    int t = 1;
    cout << t << "\n";

    while (t--) {
        int n, m, start_node, base_moves;
        vector<pair<int, int>> edges;

        if (mode == "non") {

            if (rnd.next(10) == 0) n = rnd.next(2, 50);
            else n = rnd.next(50, 300);

            if (n > 100) base_moves = rnd.next(2000, 5000);
            else base_moves = rnd.next(1000, 2000);

            for (int i = 2; i <= n; i++) {
                edges.push_back({rnd.next(1, i - 1), i});
            }

            long long max_m = min((long long)n * (n - 1) / 2, (long long)25 * n);

            int m_target = rnd.next((int)edges.size(), (int)max_m);

            set<pair<int,int>> current_edges;
            vector<int> deg(n + 1, 0);
            for(auto &e: edges) {
                if(e.first > e.second) swap(e.first, e.second);
                current_edges.insert(e);
                deg[e.first]++;
                deg[e.second]++;
            }

            int attempts = 0;
            while((int)edges.size() < m_target && attempts < 50000) {
                attempts++;
                int u = rnd.next(1, n);
                int v = rnd.next(1, n);
                if (u == v) continue;
                if (u > v) swap(u, v);
                if (current_edges.count({u, v})) continue;
                if (deg[u] >= 50 || deg[v] >= 50) continue;

                current_edges.insert({u, v});
                edges.push_back({u, v});
                deg[u]++;
                deg[v]++;
            }
        } else {

            n = rnd.next(50, 300);
            base_moves = rnd.next(1500, 4000);

            int k = rnd.next(3, min(n - 1, 50));

            if ((n * k) % 2 != 0) {

                if (n % 2 != 0) {
                    n++;
                    if (n > 300) n = 298;
                }
            }

            k = min(k, n - 1);

            bool generated = false;
            int try_graph = 0;
            while (!generated && try_graph < 20) {
                try_graph++;
                edges.clear();
                vector<int> stubs;
                stubs.reserve(n * k);
                for (int i = 1; i <= n; i++)
                    for (int j = 0; j < k; j++) stubs.push_back(i);

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

                bool possible = true;
                set<pair<int,int>> edge_set;
                vector<pair<int,int>> temp_edges;

                for (size_t i = 0; i < stubs.size(); i += 2) {
                    int u = stubs[i];
                    int v = stubs[i+1];
                    if (u == v) { possible = false; break; }
                    if (u > v) swap(u, v);
                    if (edge_set.count({u, v})) { possible = false; break; }
                    edge_set.insert({u, v});
                    temp_edges.push_back({u, v});
                }

                if (possible) {
                    DSU dsu(n);
                    int components = n;
                    for (auto &e : temp_edges) {
                        if (dsu.unite(e.first, e.second)) components--;
                    }
                    if (components == 1) {
                        edges = temp_edges;
                        generated = true;
                    }
                }
            }

            if (!generated) {
                edges.clear();
                set<pair<int,int>> edge_set;
                vector<int> deg(n + 1, 0);

                for(int i = 1; i < n; i++) edges.push_back({i, i+1});
                edges.push_back({n, 1});

                for(auto &e : edges) {
                    if (e.first > e.second) swap(e.first, e.second);
                    edge_set.insert(e);
                    deg[e.first]++; deg[e.second]++;
                }

                int target_m = min((long long)n * k / 2, (long long)25 * n);
                int attempts = 0;
                while((int)edges.size() < target_m && attempts < 50000) {
                    attempts++;
                    int u = rnd.next(1, n);
                    int v = rnd.next(1, n);
                    if(u == v) continue;
                    if(u > v) swap(u, v);
                    if(edge_set.count({u, v})) continue;
                    if(deg[u] >= 50 || deg[v] >= 50) continue;

                    edge_set.insert({u, v});
                    edges.push_back({u, v});
                    deg[u]++; deg[v]++;
                }
            }
        }

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

        start_node = rnd.next(1, n);
        m = edges.size();

        cout << n << " " << m << " " << p[start_node] << " " << base_moves << "\n";
        for (auto &e : edges) {
            cout << p[e.first] << " " << p[e.second] << "\n";
        }
    }

    return 0;
}