This is an interactive problem.

Kochiya Sanae is playing with magnets. Realizing that some of those magnets are demagnetized, she is curious to find them out.

There are $n$ magnets, which can be of the following $3$ types:

* N
* S
* - — these magnets are demagnetized.

Note that you don't know the types of these magnets beforehand.

You have a machine which can measure the force between the magnets, and you can use it at most $n+\lfloor \log_2n\rfloor$ times.

You can put some magnets to the left part of the machine and some to the right part of the machine, and launch the machine. Obviously, you can put one magnet to at most one side (you don't have to put all magnets). You can put the same magnet in different queries.

Then the machine will tell the force these magnets produce. Formally, let $n_1,s_1$ be the number of N and S magnets correspondently on the left and $n_2,s_2$ — on the right. Then the force between them would be $n_1n_2+s_1s_2-n_1s_2-n_2s_1$. Please note that the force is a signed value.

However, when the absolute value of the force is strictly larger than $n$, the machine will crash into pieces.

You need to find all magnets of type - (all demagnetized ones), without breaking the machine.

Note that the interactor is not adaptive. The types of the magnets are fixed before the start of the interaction and do not change with queries.

It is guaranteed that there are at least $2$ magnets whose type is not -, and at least $1$ magnet of type -.

Input

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

Interaction

For each test case you should start by reading an integer $n$ ($3 \leq n \leq 2000$) — the number of the magnets.

It is guaranteed that the total sum of all $n$ over all test cases doesn't exceed $2000$.

After that you can put some magnets into the machine and make a query from the statement.

You have to print each query in three lines:

* In the first line print "? l r" (without quotes) where $l$ and $r$ ($1 \leq l,r < n$, $l+r \leq n$) respectively denote the number of the magnets you put to left and right.
* In the second line print $l$ integers $a_1, \dots, a_l$ ($1 \leq a_i \leq n$, $a_i \neq a_j$ if $i \neq j$) — the indices of the magnets you put to left.
* In the third line print $r$ integers $b_1, \dots, b_r$ ($1 \leq b_i \leq n$, $b_i \neq b_j$ if $i \neq j$) — the indices of the magnets you put to right.
* The same magnet can't be put to both sides in the same query. Formally, you should guarantee that $a_i \neq b_j$ for any $i$ and $j$. However, you may leave some magnets unused.

After printing a query do not forget to output end of line and flush the output. 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.

After this, you should read an integer $F$ — the force these magnets produce.

Note that if your query is invalid(either the query limit exceeds, the machine crashes or the arguments are invalid), the interactor will terminate immediately. In this case terminate your program to receive verdict Wrong Answer instead of arbitrary verdicts.

If you are confident about your answer, use the following format to report it:

* "! k A", where $k$ is the number of magnets you found, and $A$ is an array consisting of $k$ different integers from $1$ to $n$ denoting the indices of the magnets of type - that you found. You may print elements of $A$ in arbitrary order.
* After that, if this is the last test case, you have to terminate your program; otherwise you should immediately continue to deal with the next test case.

Note that the interactor is not adaptive. The types of the magnets are fixed before the start of interaction and do not change with queries.

Example

Input

```
1
4

0

1

0

0
```

Output

```
? 1 1
3
4

? 1 2
1
2 3

? 1 1
1
4

? 1 1
1
3

! 2 3 4
```

Note

The empty lines in the sample are just for you to better understand the interaction process. You're not required to print them.

In the sample, the types of the magnets are NN--.

At first, you put the third magnet on the left and the fourth one on the right. Both of them have type -, thus no force is produced.

Then you put the first magnet on the left and the second and third one on the right. The third magnet has type -, while the other two magnets are of type N, so the force produced is $1$.

In the following two queries, the force is $0$ since there is only a magnet with property - on the right.

Then we can determine that the magnets of type - are the third and the fourth one, so we should print ! 2 3 4 and exit.

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

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

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

    }
}

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

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

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

    int t = inf.readInt(1, 100, "t");

    cout << t << endl;

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

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

        string s = inf.readToken();

        if ((int)s.length() != n) {
            quitf(_fail, "Test case %d: Hidden string length %d does not match n=%d", i + 1, (int)s.length(), n);
        }
        for (char c : s) {
            if (c != 'N' && c != 'S' && c != '-') {
                quitf(_fail, "Test case %d: Invalid character '%c' in hidden string", i + 1, c);
            }
        }

        long long limit_per_case = n + (long long)floor(log2(n));
        query_limit += limit_per_case;

        log_metrics();

        cout << n << endl;

        bool case_solved = false;
        while (!case_solved) {
            string token;

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

            if (token == "!") {

                int k;
                if (!(cin >> k)) finish(_wa, "Expected integer k after '!'");

                vector<int> ans;
                set<int> ans_set;
                for (int j = 0; j < k; ++j) {
                    int val;
                    if (!(cin >> val)) finish(_wa, "Expected magnet index");
                    if (val < 1 || val > n) finish(_wa, "Answer index out of range");
                    if (ans_set.count(val)) finish(_wa, "Duplicate index in answer");
                    ans_set.insert(val);
                    ans.push_back(val);
                }

                set<int> correct;
                for (int j = 0; j < n; ++j) {
                    if (s[j] == '-') correct.insert(j + 1);
                }

                if (ans_set == correct) {
                    case_solved = true;
                } else {
                    finish(_wa, "Incorrect magnets identified");
                }
            } else {

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

                    try {
                        l = stoi(token);
                    } catch (...) {
                        finish(_wa, "Invalid token (expected '?', '!' or integer)");
                    }
                    if (!(cin >> r)) finish(_wa, "Expected r");
                }

                if (l < 1 || r < 1 || l + r > n) {
                    finish(_wa, format("Invalid query sizes: l=%d, r=%d, n=%d", l, r, n));
                }

                vector<int> left_set, right_set;
                set<int> used;

                for (int j = 0; j < l; ++j) {
                    int val;
                    if (!(cin >> val)) finish(_wa, "Expected index in left set");
                    if (val < 1 || val > n) finish(_wa, "Index out of range in left set");
                    if (used.count(val)) finish(_wa, "Duplicate index in left set");
                    used.insert(val);
                    left_set.push_back(val);
                }

                for (int j = 0; j < r; ++j) {
                    int val;
                    if (!(cin >> val)) finish(_wa, "Expected index in right set");
                    if (val < 1 || val > n) finish(_wa, "Index out of range in right set");
                    if (used.count(val)) finish(_wa, "Duplicate or overlapping index in right set");
                    used.insert(val);
                    right_set.push_back(val);
                }

                long long sumL = 0, sumR = 0;
                for (int idx : left_set) {

                    char type = s[idx - 1];
                    if (type == 'N') sumL++;
                    else if (type == 'S') sumL--;
                }
                for (int idx : right_set) {
                    char type = s[idx - 1];
                    if (type == 'N') sumR++;
                    else if (type == 'S') sumR--;
                }

                long long force = sumL * sumR;

                if (abs(force) > n) {
                    finish(_wa, "Machine crashed (absolute force > n)");
                }

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

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

                cout << force << endl;
            }
        }
    }

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

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

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);
    string mode = opt<string>("mode", "non");

    int seed_val = 0;
    if (argc > 1) {
        try {

            seed_val = stoi(argv[1]);
        } catch (...) {
            seed_val = 0;
        }
    }

    const int SUM_LIMIT = 2000;
    int t = 1;
    vector<int> ns;

    if (seed_val == 1) {

        t = 1;
        ns = {3};
    } else if (seed_val == 2) {

        t = 1;
        ns = {SUM_LIMIT};
    } else if (seed_val == 3) {

        t = SUM_LIMIT / 3;
        ns.assign(t, 3);

        t = 100;
        ns.assign(t, 3);

    } else if (seed_val == 4) {

        t = 2;
        ns = {1000, 1000};
    } else {

        int type = rnd.next(1, 100);
        if (type <= 10) t = 1;
        else if (type <= 50) t = rnd.next(2, 10);
        else t = rnd.next(11, 100);

        if (t > 100) t = 100;

        if (t * 3 > SUM_LIMIT) t = SUM_LIMIT / 3;

        ns = rnd.partition(t, SUM_LIMIT, 3);
    }

    cout << t << endl;

    for (int n : ns) {
        cout << n << endl;

        if (mode == "non") {

            int n_charged;
            if (n == 3) {
                n_charged = 2;
            } else {
                int strat = rnd.next(100);
                if (strat < 20) n_charged = 2;
                else if (strat < 40) n_charged = n - 1;
                else if (strat < 70) n_charged = rnd.next(2, max(3, (int)sqrt(n)));
                else n_charged = rnd.next(2, n - 1);
            }

            string s(n, '-');

            int charge_type_strat = rnd.next(4);
            for (int i = 0; i < n_charged; i++) {
                char c;
                if (charge_type_strat == 0) c = 'N';
                else if (charge_type_strat == 1) c = 'S';
                else if (charge_type_strat == 2) c = (i % 2 == 0 ? 'N' : 'S');
                else c = (rnd.next(2) ? 'N' : 'S');
                s[i] = c;
            }

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

                sort(s.begin(), s.end());
            } else if (pattern_strat == 1) {

                sort(s.begin(), s.end(), greater<char>());
            } else {

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

            cout << s << endl;
        }

    }

    return 0;
}


Dabi, the galaxy-famous adventurer, has entered a long-forgotten underground city said to hide an ancient treasure. Within its pitch-black tunnels, she must find a key and reach the treasure chest before the city collapses.

The entire city can be represented as an $h \times w$ grid $( 3 \leq h , w \leq 1 6 )$ ). Each cell of this grid is one of the following types:

⚫ Empty cell, which is a traversable passage.
⚫ Wall cell, which is a solid block that cannot be entered. Teleport cell, which is an ancient device that instantly connects two distant places.

The following facts are known about this underground city:

⚫ Every cell on the grid’s boundary (i.e., topmost/bottommost row, or leftmost/rightmost column) is a wall. All wall cells are connected through four directions: north (up), south (down), east (right), and west (left)—that is, they form a single 4-directional connected component. All empty cells are connected, forming a single 4-directional connected component surrounded by walls. For every teleport cell, all eight neighboring cells are empty cells.
$\bullet$ Every teleport cell belongs to exactly one teleport pair. If Dabi steps into a teleport cell from any direction, she is immediately transported to its paired cell and then moves one additional step in the same direction she entered the teleport cell. This process never triggers another teleportation. Each teleport pair is labeled with one of the uppercase letters A, B, C, D, E, and F. Therefore, there are at most $6 \times 2 = 1 2$ teleport cells in total. There is exactly one key and one treasure chest, each placed on distinct empty cells, but neither is at Dabi’s initial position.

![](images/0871d9bb5916e1201c3a6c8a57c6f3138768bb57e20ec737ea6bb8317cc4d6a6.jpg)
Figure 1. An example configuration of the underground city $h = 7$ ; $w = 9$ ) with two teleport pairs A and B.

Dabi can perform the following two actions:

Move to one of the four adjacent cells that is not a wall. Teleportation and the subsequent extra step are considered part of ‘entering a teleport cell’ and do not count as separate actions. Pick up the key if she is on the cell with the key.

Dabi always stands on an empty cell before and after each action.

Figure 1 illustrates an example of the underground city where $h = 7$ and $w = 9$ . Teleport pair A connects the two cells marked with the letter A, and teleport pair B connects the two cells marked with the letter B. Note that Figure 1 corresponds to the city described in the attached sample.in file.

As shown in Figure 2, the teleportation process works as follows. In Figure 2(a), Dabi is standing on the cell immediately east of teleport A. When she moves west, she steps into the teleport cell marked A, is instantly transported to its paired cell, and then moves one additional step to the west, resulting in the configuration shown in Figure 2(b).

![](images/2de463e26eafb241c11f429842597fe1a6b9c89eaa9c0b7199d256620911e8fc.jpg)
Figure 2. Illustration of the teleportation process. (a) Dabi stands on the cell immediately east of teleport A. (b) After moving west, she steps into teleport cell A, is transported to its paired cell, and then moves one additional step to the west.

When Dabi picks up the key, the city begins to collapse. From that moment, she must reach the treasure cell in the minimum possible number of actions. Any longer route causes the attempt to fail.

Dabi carries a reliable compass and can always tell north, south, east, and west. By feeling the walls around her, she can sense for each of the four directions whether the adjacent cell is a wall or not. However, she does not initially know her coordinates or the overall layout of the city. At any moment, she can also sense whether her current cell contains the key or the treasure. She may stand on the key cell without immediately picking it up.

Your task is to guide Dabi through the city to obtain the key and then reach the treasure chest, obeying all movement rules. Write a program to accomplish this by interacting with the interactor through a sequence of commands.

# Interaction

This is an interactive problem. Your submitted program will interact with an interactor inside the grading server, which reads input from and writes output to your program. Your program must control Dabi by printing commands and reading the interactor’s replies. After every line of output, you must immediately flush the output.

# Initial Input

At the beginning of the interaction, the interactor provides information about Dabi’s current cell. The information is given as a single line containing six characters without spaces:

Each of the six characters is either $\bullet _ { 0 } ,$ or ‘1’. For the first four characters, $\cdot _ { 1 } ,$ means that the adjacent cell in that direction is a wall, and $\bullet _ { 0 } ,$ means that the adjacent cell in that direction is not a wall. The order of directions is north, south, east, and west. The fifth character is $\cdot _ { 1 } ,$ if the key is present on Dabi’s current cell and has not yet been picked up; otherwise, it is $\bullet _ { 0 } ,$ .
$\bullet$ The sixth character is $\bullet _ { 1 } ,$ if the treasure chest is on Dabi’s current cell; otherwise, it is $\bullet _ { 0 } ,$ .
$\bullet$ Since the key and the treasure chest are on different cells, the fifth and sixth characters are never both $\bullet _ { 1 } ,$ .

For example, $^ { \bullet \bullet } \mathrm { 1 0 0 0 1 0 ^ { \bullet } }$ means that there is a wall to the north, the other three directions are open, the unpicked key is on the current cell, and there is no treasure.

# Commands

Your program may repeatedly output exactly one of the following commands until the interactor outputs “correct” or terminates the interaction.

1. “N”, “S”, “E”, or “W”

$\bullet$ Move one step in the chosen direction—“N” (north), “S” (south), “E” (east), or “W” (west). The target cell must not be a wall. If it is a teleport cell, Dabi will be teleported according to the rules described above. Attempting to move into a wall causes the interactor to output “wrong”. 2. “K” Pick up the key on the current cell. After this action, the treasure chest opens, and from that moment Dabi must reach the treasure cell in the minimum possible number of actions. If there is no unpicked key on the current cell, the interactor outputs “wrong”.

Each command must be printed on its own line and immediately flushed. The total number of commands issued must not exceed 230,611.

# Interactor Responses

After each action, the interactor responds as follows:

. The interactor outputs “correct” if Dabi has already picked up the key and has just reached the treasure cell using the minimum possible number of actions. The interactor immediately terminates the interaction if any rule is violated—for example, a malformed command, an invalid move, attempting to pick up a nonexistent or already collected key, exceeding 230,611 actions in total, or reaching the treasure through a route that does not use the minimum possible number of actions after the key has been collected.
. Otherwise, the interactor outputs a six-character string describing Dabi’s new current cell, in the same format as the initial input.

Receiving “correct” means that your program has successfully completed the mission and should terminate gracefully. Do not forget to flush the output after printing each command.

The city layout is fixed throughout the interaction; the interactor is not adaptive.

The time and memory used by the interactor are also included in the calculation of your program’s execution time and memory usage. You can assume that the maximum time used by the interactor is 1 second and the maximum amount of memory is 64 MiB.

The following shows a sample interaction when the city layout and Dabi’s initial position are the same as in Figure 1.

# Read (Interactor’s Response)

# Sample Interaction 1

101000

	W

000000

	W

000000

	S

010000

	W

010110

	K

010100

	N

000000

	W

010100

	N

000100

	E

correct

To flush, you need to do the following right after writing a command and a newline:

fflush(stdout) in C;
std::cout << std::flush in $\mathrm { C } { + } { + }$ ;
System.out.flush() in Java or Kotlin;
sys.stdout.flush() in Python.

A testing tool is provided to help you develop your solution, so it is not mandatory to use it. If you want to use it, you can download the attachment testing_tool.py from the DOMjudge Problemset page. You can run the testing tool to see how your program interacts for a specific city layout. This testing tool can be used regardless of the language of your program as follows. The same explanation is also included in the comments of testing_tool.py.

Usage: python3 testing_tool.py -f <inputfile> <program>

Use the -f parameter to specify the input file, e.g. input.in.

Format of the input file: The first line contains two integers $h$ and $w$ . The next $h$ lines each contain a string of length ??, describing the map of the city. Each character represents a cell type as follows:

‘#’: A wall cell.
‘.’: An empty cell.
‘k’: The empty cell containing the key.
‘t’: The empty cell containing the treasure chest.
‘v’: The empty cell where Dabi initially stands.
‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’: Teleport cells, where each letter represents one teleport pair.

Example: The city shown in Figure 1 is represented as follows.

79

#########

###...###

#...A.v##

#.B.....#

#...A.Bt#

##k.....#

#########

The tool is provided as-is, and you should feel free to make whatever alterations or augmentations you like to it. Note that it is not guaranteed that a program that passes the testing tool will be accepted. For example, the testing tool does not verify whether Dabi reaches the treasure chest using the minimum possible number of actions after picking up the key; instead, it only reports how many actions were taken.

If you have a $\mathrm { C } { + } { + }$ solution stored in a file called “sol.cpp”, you must first compile using $^ { 6 6 } \mathrm { { g } + + }$ sol.cpp -o sol” and then invoke the testing tool with:

If you have a Python solution that you would run using “pypy3 solution.py”, you can invoke the testing tool with:

python3 testing_tool.py -f input.in pypy3 solution.py

If you have a Java solution that you would run using “java MyClass”, you can invoke the testing tool with:

python3 testing_tool.py -f input.in java MyClass

If you have a Kotlin solution that you would run using “kotlin SolutionKt”, you can invoke the testing tool with:

python3 testing_tool.py -f input.in kotlin SolutionKt

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

using namespace std;

struct Pos {
    int r = 0;
    int c = 0;
};

static int queries = 0;
static constexpr int QUERY_LIMIT = 230611;

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

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

static bool in_bounds(int r, int c, int h, int w) {
    return 0 <= r && r < h && 0 <= c && c < w;
}

static char wall_char(const vector<string>& g, int r, int c) {
    if (!in_bounds(r, c, (int)g.size(), (int)g[0].size())) {
        return '#';
    }
    return g[r][c];
}

static string observation(
    const vector<string>& g,
    Pos p,
    Pos key_pos,
    Pos treasure_pos,
    bool key_picked
) {
    static const int DR[4] = {-1, 1, 0, 0};
    static const int DC[4] = {0, 0, 1, -1};

    string s;
    s.reserve(6);
    for (int d = 0; d < 4; d++) {
        const char ch = wall_char(g, p.r + DR[d], p.c + DC[d]);
        s.push_back(ch == '#' ? '1' : '0');
    }
    const bool key_here = (!key_picked && p.r == key_pos.r && p.c == key_pos.c);
    const bool treasure_here = (p.r == treasure_pos.r && p.c == treasure_pos.c);
    s.push_back(key_here ? '1' : '0');
    s.push_back(treasure_here ? '1' : '0');
    return s;
}

static bool is_teleport(char ch) {
    return 'A' <= ch && ch <= 'F';
}

static Pos step_once(
    const vector<string>& g,
    const unordered_map<char, array<Pos, 2>>& tele,
    Pos cur,
    int dr,
    int dc
) {
    const int h = (int)g.size();
    const int w = (int)g[0].size();

    const int nr = cur.r + dr;
    const int nc = cur.c + dc;
    if (!in_bounds(nr, nc, h, w)) {
        quit_with(_wa, "Move out of bounds");
    }
    const char to = g[nr][nc];
    if (to == '#') {
        quit_with(_wa, "Move into wall");
    }
    if (!is_teleport(to)) {
        return Pos{nr, nc};
    }

    auto it = tele.find(to);
    if (it == tele.end()) {
        quit_with(_wa, "Teleport missing pair");
    }
    const array<Pos, 2>& pair = it->second;
    const Pos a = pair[0];
    const Pos b = pair[1];

    Pos other = a;
    if (a.r == nr && a.c == nc) {
        other = b;
    } else if (b.r == nr && b.c == nc) {
        other = a;
    } else {
        quit_with(_wa, "Teleport pair mismatch");
    }

    const int fr = other.r + dr;
    const int fc = other.c + dc;
    if (!in_bounds(fr, fc, h, w)) {
        quit_with(_wa, "Teleport extra step out of bounds");
    }
    const char after = g[fr][fc];
    if (after == '#') {
        quit_with(_wa, "Teleport extra step into wall");
    }

    return Pos{fr, fc};
}

static int shortest_after_key(
    const vector<string>& g,
    const unordered_map<char, array<Pos, 2>>& tele,
    Pos key_pos,
    Pos treasure_pos
) {
    const int h = (int)g.size();
    const int w = (int)g[0].size();
    const int total = h * w;
    auto id = [&](Pos p) { return p.r * w + p.c; };

    vector<int> dist(total, -1);
    queue<Pos> q;
    dist[id(key_pos)] = 0;
    q.push(key_pos);

    static const int DR[4] = {-1, 1, 0, 0};
    static const int DC[4] = {0, 0, 1, -1};

    while (!q.empty()) {
        Pos cur = q.front();
        q.pop();
        const int d0 = dist[id(cur)];
        if (cur.r == treasure_pos.r && cur.c == treasure_pos.c) {
            return d0;
        }
        for (int dir = 0; dir < 4; dir++) {
            const int nr = cur.r + DR[dir];
            const int nc = cur.c + DC[dir];
            if (!in_bounds(nr, nc, h, w)) {
                continue;
            }
            if (g[nr][nc] == '#') {
                continue;
            }
            Pos nxt = step_once(g, tele, cur, DR[dir], DC[dir]);
            const int nid = id(nxt);
            if (dist[nid] != -1) {
                continue;
            }
            dist[nid] = d0 + 1;
            q.push(nxt);
        }
    }

    return -1;
}

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

    const int h = inf.readInt(3, 16, "h");
    inf.readSpace();
    const int w = inf.readInt(3, 16, "w");
    inf.readEoln();

    vector<string> g(h);
    for (int i = 0; i < h; i++) {

        g[i] = inf.readLine();
        if ((int)g[i].size() != w) {
            quit_with(_fail, "Bad case: row length mismatch");
        }
    }

    Pos start{-1, -1};
    Pos key_pos{-1, -1};
    Pos treasure_pos{-1, -1};
    unordered_map<char, vector<Pos>> tele_raw;
    for (int r = 0; r < h; r++) {
        for (int c = 0; c < w; c++) {
            const char ch = g[r][c];
            if (ch == 'v') {
                start = Pos{r, c};
                g[r][c] = '.';
            } else if (ch == 'k') {
                key_pos = Pos{r, c};
                g[r][c] = '.';
            } else if (ch == 't') {
                treasure_pos = Pos{r, c};
                g[r][c] = '.';
            } else if (is_teleport(ch)) {
                tele_raw[ch].push_back(Pos{r, c});
            } else if (ch == '#' || ch == '.') {

            } else {
                quit_with(_fail, "Bad case: unknown cell type");
            }
        }
    }

    if (start.r < 0 || key_pos.r < 0 || treasure_pos.r < 0) {
        quit_with(_fail, "Bad case: missing v/k/t");
    }

    unordered_map<char, array<Pos, 2>> tele;
    for (auto& [ch, v] : tele_raw) {
        if (v.size() != 2) {
            quit_with(_fail, "Bad case: teleport not paired");
        }
        tele[ch] = {v[0], v[1]};
    }

    Pos cur = start;
    bool key_picked = false;
    int moves_after_key = 0;
    int best_after_key = -1;

    cout << observation(g, cur, key_pos, treasure_pos, key_picked) << endl;

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

        queries++;
        if (queries > QUERY_LIMIT) {
            quit_with(_wa, "Too many commands");
        }

        if (cmd == "K") {
            if (key_picked) {
                cout << "wrong" << endl;
                quit_with(_wa, "Key already picked");
            }
            if (!(cur.r == key_pos.r && cur.c == key_pos.c)) {
                cout << "wrong" << endl;
                quit_with(_wa, "Pick key on wrong cell");
            }
            key_picked = true;
            moves_after_key = 0;
            best_after_key = shortest_after_key(g, tele, key_pos, treasure_pos);
            if (best_after_key < 0) {
                quit_with(_fail, "Bad case: treasure unreachable after key");
            }
            cout << observation(g, cur, key_pos, treasure_pos, key_picked) << endl;
            continue;
        }

        int dr = 0;
        int dc = 0;
        if (cmd == "N") {
            dr = -1;
        } else if (cmd == "S") {
            dr = 1;
        } else if (cmd == "E") {
            dc = 1;
        } else if (cmd == "W") {
            dc = -1;
        } else {
            quit_with(_pe, "Invalid command");
        }

        cur = step_once(g, tele, cur, dr, dc);
        if (key_picked) {
            moves_after_key++;
        }

        if (key_picked && cur.r == treasure_pos.r && cur.c == treasure_pos.c) {
            if (moves_after_key == best_after_key) {
                cout << "correct" << endl;
                quit_with(_ok, "Correct");
            }
            cout << "wrong" << endl;
            quit_with(_wa, "Not optimal path after key");
        }

        cout << observation(g, cur, key_pos, treasure_pos, key_picked) << endl;
    }
}

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

using namespace std;

const int MIN_SIDE = 3;
const int MAX_SIDE = 16;

struct Grid {
    int h, w;
    vector<string> grid;

    Grid(int _h, int _w) : h(_h), w(_w) {
        grid.resize(h, string(w, '#'));
    }

    bool is_valid(int r, int c) const {
        return r >= 0 && r < h && c >= 0 && c < w;
    }

    bool is_wall(int r, int c) const {
        if (!is_valid(r, c)) return true;
        return grid[r][c] == '#';
    }

    bool is_empty_type(int r, int c) const {
        if (!is_valid(r, c)) return false;
        char C = grid[r][c];
        return C == '.' || C == 'k' || C == 't' || C == 'v';
    }

    bool check() {

        for (int r = 0; r < h; r++) {
            if (grid[r][0] != '#' || grid[r][w-1] != '#') return false;
        }
        for (int c = 0; c < w; c++) {
            if (grid[0][c] != '#' || grid[h-1][c] != '#') return false;
        }

        map<char, int> counts;
        vector<pair<int,int>> tels;
        for(int r = 0; r < h; ++r){
            for(int c = 0; c < w; ++c){
                char C = grid[r][c];
                if(C >= 'A' && C <= 'F'){
                    tels.push_back({r,c});
                    counts[C]++;

                    for(int dr = -1; dr <= 1; ++dr){
                        for(int dc = -1; dc <= 1; ++dc){
                            if(dr == 0 && dc == 0) continue;
                            if(!is_empty_type(r + dr, c + dc)) return false;
                        }
                    }
                }
            }
        }
        for(auto kv : counts) if(kv.second != 2) return false;

        int wall_cnt = 0;
        int wr = -1, wc = -1;
        for(int r = 0; r < h; ++r){
            for(int c = 0; c < w; ++c){
                if(grid[r][c] == '#'){
                    wall_cnt++;
                    wr = r; wc = c;
                }
            }
        }
        if(wall_cnt > 0) {
            int visited_walls = 0;
            vector<vector<bool>> vis(h, vector<bool>(w, false));
            queue<pair<int,int>> q;
            q.push({wr, wc});
            vis[wr][wc] = true;
            visited_walls++;
            int dr[] = {0,0,1,-1};
            int dc[] = {1,-1,0,0};
            while(!q.empty()){
                auto [r, c] = q.front(); q.pop();
                for(int i=0; i<4; ++i){
                    int nr = r + dr[i], nc = c + dc[i];
                    if(is_valid(nr, nc) && grid[nr][nc] == '#' && !vis[nr][nc]){
                        vis[nr][nc] = true;
                        visited_walls++;
                        q.push({nr, nc});
                    }
                }
            }
            if(visited_walls != wall_cnt) return false;
        }

        int empty_cnt = 0;
        int er = -1, ec = -1;
        for(int r = 0; r < h; ++r){
            for(int c = 0; c < w; ++c){
                if(is_empty_type(r, c)){
                    empty_cnt++;
                    er = r; ec = c;
                }
            }
        }
        if(empty_cnt == 0) return false;

        int visited_empty = 0;
        vector<vector<bool>> vis(h, vector<bool>(w, false));
        queue<pair<int,int>> q;
        q.push({er, ec});
        vis[er][ec] = true;
        visited_empty++;
        int dr[] = {0,0,1,-1};
        int dc[] = {1,-1,0,0};
        while(!q.empty()){
            auto [r, c] = q.front(); q.pop();
            for(int i=0; i<4; ++i){
                int nr = r + dr[i], nc = c + dc[i];
                if(is_valid(nr, nc) && is_empty_type(nr, nc) && !vis[nr][nc]){
                    vis[nr][nc] = true;
                    visited_empty++;
                    q.push({nr, nc});
                }
            }
        }
        if(visited_empty != empty_cnt) return false;

        bool has_k = false, has_t = false, has_v = false;
        for(int r=0; r<h; ++r) for(int c=0; c<w; ++c) {
            if(grid[r][c] == 'k') has_k = true;
            if(grid[r][c] == 't') has_t = true;
            if(grid[r][c] == 'v') has_v = true;
        }
        return has_k && has_t && has_v;
    }
};

Grid generate_random(int h, int w) {
    int max_attempts = 1000;
    for (int attempt = 0; attempt < max_attempts; ++attempt) {
        Grid g(h, w);

        int max_pairs = (h < 5 || w < 5) ? 0 : 6;
        int num_pairs = rnd.next(0, max_pairs);
        if (num_pairs > 0 && rnd.next(3) == 0) num_pairs = rnd.next(0, num_pairs);

        vector<pair<int,int>> tels;
        int fails = 0;
        for(int i = 0; i < num_pairs * 2; ++i) {
            int r = rnd.next(2, h - 3);
            int c = rnd.next(2, w - 3);

            bool ok = true;
            for(auto p : tels) {
                if(max(abs(p.first - r), abs(p.second - c)) < 2) {
                    ok = false; break;
                }
            }
            if(ok) tels.push_back({r, c});
            else { i--; fails++; if(fails > 100) break; }
        }
        if(tels.size() % 2 != 0) tels.pop_back();

        vector<vector<bool>> forced_empty(h, vector<bool>(w, false));
        for(size_t i = 0; i < tels.size(); ++i) {
            char label = 'A' + (i / 2);
            g.grid[tels[i].first][tels[i].second] = label;
            for(int dr = -1; dr <= 1; ++dr) {
                for(int dc = -1; dc <= 1; ++dc) {
                    if(dr == 0 && dc == 0) continue;
                    forced_empty[tels[i].first + dr][tels[i].second + dc] = true;
                }
            }
        }

        for(int r = 0; r < h; ++r) for(int c = 0; c < w; ++c)
            if(forced_empty[r][c]) g.grid[r][c] = '.';

        for(int r = 1; r < h - 1; ++r) {
            for(int c = 1; c < w - 1; ++c) {
                if(g.grid[r][c] == '#') {
                    if(rnd.next(100) < 60) g.grid[r][c] = '.';
                }
            }
        }

        int attempts = 0;
        while(attempts++ < 5) {
            vector<pair<int,int>> empties;
            for(int r=0; r<h; ++r) for(int c=0; c<w; ++c) if(g.is_empty_type(r,c)) empties.push_back({r,c});

            if(empties.empty()) { g.grid[h/2][w/2] = '.'; continue; }

            vector<vector<int>> vis(h, vector<int>(w, 0));
            int comp = 0;
            int dr[] = {0,0,1,-1};
            int dc[] = {1,-1,0,0};
            for(auto p : empties) {
                if(!vis[p.first][p.second]) {
                    comp++;
                    queue<pair<int,int>> q;
                    q.push(p);
                    vis[p.first][p.second] = comp;
                    while(!q.empty()){
                        auto [r, c] = q.front(); q.pop();
                        for(int i=0; i<4; ++i){
                            int nr = r + dr[i], nc = c + dc[i];
                            if(g.is_valid(nr, nc) && g.is_empty_type(nr, nc) && !vis[nr][nc]){
                                vis[nr][nc] = comp;
                                q.push({nr, nc});
                            }
                        }
                    }
                }
            }

            if(comp <= 1) break;

            vector<vector<int>> dist(h, vector<int>(w, -1));
            vector<vector<pair<int,int>>> parent(h, vector<pair<int,int>>(w, {-1,-1}));
            queue<pair<int,int>> q;

            for(int r=0; r<h; ++r) for(int c=0; c<w; ++c) if(vis[r][c] == 1) {
                dist[r][c] = 0;
                q.push({r,c});
            }

            int found_r = -1, found_c = -1;
            while(!q.empty()){
                auto [r,c] = q.front(); q.pop();
                if(vis[r][c] != 0 && vis[r][c] != 1) {
                    found_r = r; found_c = c;
                    break;
                }

                vector<int> dirs = {0,1,2,3};
                shuffle(dirs.begin(), dirs.end());
                for(int i : dirs){
                    int nr = r + dr[i], nc = c + dc[i];
                    if(g.is_valid(nr, nc) && nr > 0 && nr < h-1 && nc > 0 && nc < w-1) {
                        if(g.grid[nr][nc] >= 'A' && g.grid[nr][nc] <= 'F') continue;
                        if(dist[nr][nc] == -1){
                            dist[nr][nc] = dist[r][c] + 1;
                            parent[nr][nc] = {r,c};
                            q.push({nr, nc});
                        }
                    }
                }
            }

            if(found_r != -1) {
                int curr = found_r, curc = found_c;
                while(vis[curr][curc] != 1) {
                    if(g.grid[curr][curc] == '#') g.grid[curr][curc] = '.';
                    pair<int,int> p = parent[curr][curc];
                    curr = p.first; curc = p.second;
                }
            } else {
                break;
            }
        }

        vector<pair<int,int>> empties;
        for(int r=0; r<h; ++r) for(int c=0; c<w; ++c) if(g.is_empty_type(r,c)) empties.push_back({r,c});

        if(empties.size() < 3) continue;
        shuffle(empties.begin(), empties.end());

        g.grid[empties[0].first][empties[0].second] = 'v';
        g.grid[empties[1].first][empties[1].second] = 'k';
        g.grid[empties[2].first][empties[2].second] = 't';

        if(g.check()) return g;
    }

    Grid g(h, w);
    for(int r = 1; r < h - 1; ++r)
        for(int c = 1; c < w - 1; ++c)
            g.grid[r][c] = '.';
    g.grid[1][1] = 'v';
    g.grid[1][2] = 'k';
    g.grid[1][3] = 't';
    return g;
}

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

    string mode = opt<string>("mode", "non");
    int seed_val = atoi(argv[1]);

    int h, w;
    while(true) {
        if (seed_val == 1) { h = 3; w = 5; }
        else if (seed_val == 2) { h = 16; w = 16; }
        else if (seed_val == 3) { h = 5; w = 5; }
        else {
            h = rnd.next(MIN_SIDE, MAX_SIDE);
            w = rnd.next(MIN_SIDE, MAX_SIDE);
            if (rnd.next(2)) {
                h = rnd.next(10, MAX_SIDE);
                w = rnd.next(10, MAX_SIDE);
            }
        }

        if ((h - 2) * (w - 2) >= 3) break;
        if (seed_val <= 3) {

             h = 6; w = 6; break;
        }
    }

    if (mode == "adp") {
        cout << h << " " << w << endl;
    } else {
        Grid g = generate_random(h, w);
        cout << g.h << " " << g.w << endl;
        for(const auto& row : g.grid) {
            cout << row << endl;
        }
    }

    return 0;
}


### Problem Statement

**This is an interactive task.**

AtCoDeer the deer came across $N$ people. For convenience, the people are numbered $0$ through $N-1$.
Among them, $A$ are *honest* and the remaining $B(=N-A)$ are *unkind*.
All of these $N$ people know who are honest and who are unkind, but AtCoDeer only knows that there are $A$ honest and $B$ unkind people.
He is trying to identify all of the honest people by asking questions to these $N$ people.
For one question, AtCoDeer selects $a$ and $b$ $(0≤a,b≤N-1)$, and asks person $a$ the following question: "Is person $b$ honest?"

An honest person will always answer correctly by "Yes" or "No".
An unkind person, however, will answer by selecting "Yes" or "No" **arbitrarily**.
That is, the algorithm used by an unkind person may not be simple one such as always lying or giving random fifty-fifty answers.

AtCoDeer can ask at most $2N$ questions. He will ask questions one by one, and the responses to the previous questions can be used when deciding the next question to ask.

Identify all of the honest people.
If it is impossible (more formally, if, for any strategy of asking $2N$ questions, there exists a strategy for unkind people to answer the questions so that there are two or more possible sets of the honest people), report that fact.

### Constraints

* $1≤A,B≤2000$

### Input and Output

First, $A$ and $B$ are given from Standard Input in the following format:

```
$A$ $B$
```

If identifying the honest people is impossible, the program must immediately print the following output and terminate itself:

```
Impossible
```

Otherwise, the program shall ask questions.
Each question must be written to Standard Output in the following format:

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

Here, $a$ and $b$ must be integers between $0$ and $N-1$ (inclusive).
The response to the question will be given from Standard Input in the following format:

```
$ans$
```

Here, $ans$ is either `Y` or `N`.
`Y` represents "Yes"; `N` represents "No".

Finally, the answer must be written to Standard Output in the following format:

```
! $s_0s_1...s_{N-1}$
```

Here, $s_i$ must be `1` if person $i$ is honest, and `0` if person $i$ is unkind.

### Judgement

* **After each output, you must flush Standard Output.** Otherwise you may get `TLE`.
* After you print the answer, the program must be terminated immediately. Otherwise, the behavior of the judge is undefined.
* When your output is invalid or incorrect, the behavior of the judge is undefined (it does not necessarily give `WA`).

### Samples

In the following sample, $A = 2$, $B = 1$, and the answer is `101`.

| Input | Output |
| --- | --- |
| $2$ $1$ |  |
|  | $?$ $0$ $1$ |
| $N$ |  |
|  | $?$ $0$ $2$ |
| $Y$ |  |
|  | $?$ $1$ $0$ |
| $Y$ |  |
|  | $?$ $2$ $0$ |
| $Y$ |  |
|  | $?$ $2$ $2$ |
| $Y$ |  |
|  | $!$ $101$ |

In the following sample, $A = 1$, $B = 2$, and the answer is `Impossible`.

| Input | Output |
| --- | --- |
| $1$ $2$ |  |
|  | $Impossible$ |

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

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

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 safe_stoi(const string& s) {
    try {
        size_t idx;
        int val = stoi(s, &idx);
        if (idx != s.size()) return -1;
        return val;
    } catch (...) {
        return -1;
    }
}

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

    int A = inf.readInt();
    int B = inf.readInt();
    string S = inf.readToken();

    int N = A + B;
    query_limit = 2 * N;

    bool possible = (A > B);

    if ((int)S.size() != N) {
        finish(_fail, "Generator error: S size does not match A+B");
    }

    log_metrics();

    cout << A << " " << B << endl;

    while (true) {

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

        string token;
        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF (contestant terminated early)");
        }

        string up = token;
        for (auto &c : up) c = toupper(c);
        if (up == "IMPOSSIBLE") {
            if (!possible) {
                finish(_ok, "Correctly reported Impossible");
            } else {
                finish(_wa, "Reported Impossible but solution exists (A > B)");
            }
        }

        if (token[0] == '!') {
            string ans;
            if (token.size() > 1) {
                ans = token.substr(1);
            } else {
                if (!(cin >> ans)) finish(_pe, "Expected answer string after '!'");
            }

            if (!possible) {
                finish(_wa, "Reported a solution but it was Impossible (A <= B)");
            }

            if (ans.size() != (size_t)N) {
                finish(_pe, "Answer string length mismatch");
            }

            if (ans == S) {
                finish(_ok, "Correct");
            } else {
                finish(_wa, "Incorrect assignment");
            }
        }

        bool is_query = false;
        string sa, sb;
        int a = -1, b = -1;

        if (token[0] == '?') {
            is_query = true;

            if (token.size() > 1) {
                sa = token.substr(1);
            } else {
                if (!(cin >> sa)) finish(_pe, "Expected a after '?'");
            }
            if (!(cin >> sb)) finish(_pe, "Expected b after a");
        } else {

            if (isdigit(token[0]) || (token.size() > 1 && token[0] == '-' && isdigit(token[1]))) {
                is_query = true;
                sa = token;
                if (!(cin >> sb)) finish(_pe, "Expected b after a");
            } else {
                finish(_pe, "Invalid token: " + token);
            }
        }

        if (is_query) {

            if (!possible) {
                finish(_wa, "Problem is Impossible (A <= B), expected 'Impossible' immediately");
            }

            a = safe_stoi(sa);
            b = safe_stoi(sb);

            if (a < 0 || a >= N || b < 0 || b >= N) {
                finish(_pe, "Query indices out of bounds");
            }

            queries++;

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

            char response = '?';

            if (S[a] == '1') {

                response = (S[b] == '1' ? 'Y' : 'N');
            } else {

                response = (S[b] == '1' ? 'N' : 'Y');
            }

            cout << response << endl;
        }
    }

    return 0;
}

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

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

static int A, B, N;
static vector<int> roles;

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

template<typename... Args>
void finish(TResult verdict, const char* fmt, Args... args) {
    if (finished) return;
    finished = true;
    log_metrics();
    quitf(verdict, fmt, args...);
}

string get_reply(int u, int v) {

    if (roles[u] == 1) {
        return (roles[v] == 1) ? "Y" : "N";
    }

    else {
        return (roles[v] == 0) ? "Y" : "N";
    }
}

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

    A = inf.readInt();
    B = inf.readInt();
    N = A + B;
    query_limit = 2LL * N;

    if (!inf.seekEof()) {
        string s = inf.readToken();

        if ((int)s.size() == N) {
            for (char c : s) {
                roles.push_back(c - '0');
            }
        } else {

             roles.clear();
        }
    }

    if (roles.empty()) {
        roles.assign(N, 0);
        for (int i = 0; i < A; i++) roles[i] = 1;
        shuffle(roles.begin(), roles.end());
    }

    cout << A << " " << B << endl;
    log_metrics();

    while (true) {
        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (no solution printed)");
        }

        if (token == "Impossible") {
            if (A <= B) finish(_ok, "Correct (Impossible)");
            else finish(_wa, "Reported Impossible but solution exists (A > B)");
        }

        if (token[0] == '!') {
            string ans_str;
            if (token.size() > 1) {
                ans_str = token.substr(1);
            } else {
                if (!(cin >> ans_str)) finish(_pe, "EOF after '!'");
            }

            if (A <= B) {
                finish(_wa, "Reported solution but expected Impossible (A <= B)");
            }

            if ((int)ans_str.size() != N) {
                finish(_pe, "Answer string length mismatch (expected %d, got %d)", N, (int)ans_str.size());
            }

            bool ok = true;
            for (int i = 0; i < N; i++) {
                int val = ans_str[i] - '0';
                if (val != 0 && val != 1) finish(_pe, "Invalid character in answer string: '%c'", ans_str[i]);
                if (val != roles[i]) ok = false;
            }

            if (ok) finish(_ok, "Correct assignment");
            else finish(_wa, "Incorrect assignment");
        }

        int u = -1, v = -1;
        bool parse_error = false;

        if (token[0] == '?') {
            if (token.size() > 1) {
                try {
                    u = stoi(token.substr(1));
                } catch (...) { parse_error = true; }
            } else {
                if (!(cin >> u)) parse_error = true;
            }
        } else {

            try {
                size_t idx;
                u = stoi(token, &idx);
                if (idx != token.size()) parse_error = true;
            } catch (...) { parse_error = true; }
        }

        if (parse_error) {
            finish(_pe, "Invalid token or format: %s", token.c_str());
        }

        if (!(cin >> v)) {
            finish(_pe, "EOF reading v");
        }

        if (u < 0 || u >= N || v < 0 || v >= N) {
            finish(_pe, "Indices out of bounds: %d %d", u, v);
        }

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

        string reply = get_reply(u, v);
        cout << reply << endl;

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

    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 seed_val = atoi(argv[1]);

    int A = 1, B = 1;

    if (seed_val == 1) {
        A = 1; B = 1;
    } else if (seed_val == 2) {
        A = 1; B = 2;
    } else if (seed_val == 3) {
        A = 2; B = 1;
    } else if (seed_val == 4) {
        A = 2000; B = 2000;
    } else if (seed_val == 5) {
        A = 2000; B = 1999;
    } else if (seed_val == 6) {
        A = 1000; B = 1000;
    } else if (seed_val == 7) {
        A = 1001; B = 1000;
    } else {

        int type = rnd.next(1, 100);

        if (type <= 40) {

            A = rnd.next(1, 2000);
            B = rnd.next(A, 2000);
        } else if (type <= 70) {

            B = rnd.next(1, 1999);
            A = B + 1;
        } else {

            B = rnd.next(1, 1998);
            A = rnd.next(B + 2, 2000);
        }
    }

    cout << A << " " << B << endl;

    if (mode == "non") {
        string s = "";
        s.reserve(A + B);
        for (int i = 0; i < A; i++) s += '1';
        for (int i = 0; i < B; i++) s += '0';

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

        cout << s << endl;
    }

    return 0;
}


### Problem Statement

**This problem is interactive.**

You are given a positive integer $N$.

Snuke secretly holds a permutation $P=(P_1,P_2,\dots,P_N)$ of $(1,2,\dots,N)$ and a sequence $A=(A_1,A_2,\dots,A_N)$ of positive integers of length $N$. **It is guaranteed that $P_1<P_2$.**

You may send up to $2N$ queries to Snuke. A query is of the following form:

* Specify two **distinct** positive integers $s$ and $t$ with $1\leq s,t\leq N$, and you will be given the value of $\displaystyle \sum_{i=\min(P_s,P_t)}^{\max(P_s,P_t)}A_i$.

Determine $P$ and $A$.

### Constraints

* $3\leq N\leq 5000$
* $1\leq P_i\leq N$ $(1\leq i\leq N)$
* $P_i\ne P_j$ for $i\ne j$.
* $P_1<P_2$
* $1\leq A_i\leq 10^9$ $(1\leq i\leq N)$
* $N$, $P_i$, and $A_i$ are integers.
* $P$ and $A$ are fixed before the interaction with the judge.

### Input/Output

This problem is interactive.

First, $N$ is given from Standard Input:

```
$N$
```

Next, you may send at most $2N$ queries to Snuke. When sending a query by specifying two **distinct** positive integers $s,t$, output in the following format. Do not forget to include a newline at the end.

```
? $s$ $t$
```

After sending a query, you will receive a response from Snuke in the following format:

```
$X$
```

Here, $X$ is an integer:

* If $X\ne -1$, then $X$ is the value of $\displaystyle \sum_{i=\min(P_s,P_t)}^{\max(P_s,P_t)}A_i$.
* If $X=-1$, then either $s,t$ do not satisfy the constraints or you have sent more than $2N$ queries.
  + In this case, your program is judged as incorrect and must terminate immediately.

Once you have determined $P$ and $A$, output your answer in the following format. This output does not count as a query.

```
! $P_1$ $P_2$ $\dots$ $P_N$ $A_1$ $A_2$ $\dots$ $A_N$
```

**Note that $P_1<P_2$.** After this output, terminate your program immediately.

If you output anything that does not follow the above formats, `-1` will be given as input.

```
-1
```

In that case, your program is judged as incorrect and must terminate immediately.

### Notes

* **After every output, be sure to end with a newline and flush the standard output. Failure to do so may result in a TLE.**
* When you output your answer, or receive `-1` from standard input, terminate your program immediately. Otherwise, the outcome is indeterminate.
* Note that extra newlines may be considered as an output format error.
* **The judge system for this problem is not adaptive.** That is, $P$ and $A$ are determined before the interaction with the judge and will not be changed at any point.

### Sample Interaction

For $N=6$, $P=(2,4,6,5,3,1)$, and $A=(1,9,2,25,2,9)$, here is an example of an interaction.

| Input | Output | Explanation |
| --- | --- | --- |
| `6` |  | First, the integer $N$ is given from standard input. |
|  | `? 1 2` | A query is sent to Snuke with $s=1$, $t=2$. |
| `36` |  | Since the query satisfies the constraints, the value $36$, which is equal to $\displaystyle \sum_{i=\min(P_1,P_2)}^{\max(P_1,P_2)}A_i$, is returned. |
|  | `? 2 5` | A query is sent to Snuke with $s=2$, $t=5$. |
| `27` |  | Since the query satisfies the constraints, the value $27$, which is equal to $\displaystyle \sum_{i=\min(P_2,P_5)}^{\max(P_2,P_5)}A_i$, is returned. |
|  | `! 2 4 6 5 3 1 1 9 2 25 2 9` | You report that $P$ and $A$ have been determined. After this output, the program should terminate immediately, and it will be judged as correct. |

Note that this is just one example of an interaction. In particular, it is not guaranteed that $P$ and $A$ can be uniquely determined from the queries and responses shown above.

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

    }
}

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

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int n = inf.readInt();

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

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

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

    query_limit = 2LL * n;

    log_metrics();

    cout << n << endl;

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

    while (true) {
        string token;

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

        if (token == "!") {

            vector<int> user_p(n);
            vector<long long> user_a(n);

            for(int i = 0; i < n; ++i) {
                string s;
                if (!(cin >> s)) finish(_wa, "EOF reading answer P");
                try {
                    user_p[i] = stoi(s);
                } catch (...) {
                    finish(_wa, "Invalid integer format in answer P");
                }
            }

            for(int i = 0; i < n; ++i) {
                string s;
                if (!(cin >> s)) finish(_wa, "EOF reading answer A");
                try {
                    user_a[i] = stoll(s);
                } catch (...) {
                    finish(_wa, "Invalid integer format in answer A");
                }
            }

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

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

            if (ok) {
                finish(_ok, "Correct answer");
            } else {
                finish(_wa, "Wrong answer (mismatch in P or A)");
            }

        } else {

            int s, t;

            if (token == "?") {
                if (!(cin >> s >> t)) finish(_wa, "EOF reading query parameters");
            } else {

                try {
                    s = stoi(token);
                } catch (...) {
                    finish(_wa, "Invalid query format (expected '?' or integer index)");
                }
                if (!(cin >> t)) finish(_wa, "EOF reading query parameter t");
            }

            if (s < 1 || s > n || t < 1 || t > n || s == t) {
                cout << -1 << endl;
                finish(_wa, "Invalid query parameters (indices out of bounds or s==t)");
            }

            queries++;

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

            if (queries > query_limit) {

                cout << -1 << endl;
                finish(_wa, "Query limit exceeded");
            }

            if (queries > hard_cap) {
                cout << -1 << endl;
                finish(_pe, "Hard query limit exceeded (potential infinite loop)");
            }

            int val_s = p[s - 1];
            int val_t = p[t - 1];

            int range_min = min(val_s, val_t);
            int range_max = max(val_s, val_t);

            long long result = pref[range_max] - pref[range_min - 1];

            cout << result << 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");

    int min_n = 3;
    int max_n = 5000;
    long long max_val = 1000000000LL;

    string seed_str = argv[1];
    int n;

    if (seed_str == "1") {
        n = min_n;
    } else if (seed_str == "2") {
        n = max_n;
    } else if (seed_str == "3") {
        n = rnd.next(min_n, 20);
    } else {

        if (rnd.next(3) == 0) {
            n = rnd.next(min_n, 100);
        } else {
            n = rnd.next(max_n / 2, max_n);
        }
    }

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

    vector<int> p = rnd.perm(n, 1);

    if (p[0] > p[1]) {
        swap(p[0], p[1]);
    }

    vector<long long> a(n);
    int type;

    if (seed_str == "1") type = 0;
    else if (seed_str == "2") type = 1;
    else if (seed_str == "3") type = 2;
    else type = rnd.next(5);

    if (type == 0) {

        for (int i = 0; i < n; ++i) a[i] = rnd.next(1LL, 100LL);
    } else if (type == 1) {

        for (int i = 0; i < n; ++i) a[i] = rnd.next(max_val - 1000, max_val);
    } else if (type == 2) {

        for (int i = 0; i < n; ++i) a[i] = (1LL << rnd.next(0, 29));
    } else if (type == 3) {

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

        for (int i = 0; i < n; ++i) a[i] = rnd.next(1LL, max_val);
    }

    cout << n << endl;
    println(p);
    println(a);

    return 0;
}


Do you know what tubular bells are? They are a musical instrument made up of cylindrical metal tubes. In an orchestra, tubular bells are used to mimic the ringing of bells.

Mike has tubular bells, too! They consist of $n$ tubes, and each of the tubes has a length that can be expressed by a integer from $l$ to $r$ inclusive. It is clear that the lengths of all the tubes are different (it makes no sense to make the same tubes). It is also known that $r-l+1 = n$.

Formally, we can say that Mike's tubular bells are described by a permutation $a$ of length $n$ that contains all numbers from $l$ to $r$ inclusive, with $a_i$ denoting the length of the $i$-th tube.

You are offered an interesting task: to guess what Mike's instrument looks like. Simply, you must guess the permutation.

Mike won't tell you $l$ or $r$. He will only tell you $n$, and will allow you to ask no more than $n + 5000$ queries.

In each query, you name two positive integers $x$, $y$ such that $1 \le x, y \le n, x \neq y$. In response to this query, the program written by Mike will give you $\mathrm{lcm}(a_x, a_y)$, where $\mathrm{lcm}(c,d)$ denotes the least common multiple of $c$ and $d$.

Solve Mike's problem!

Input

Each test contains multiple test cases.

The first line contains one positive integer $t$ ($1 \le t \le 20$), denoting the number of test cases. Description of the test cases follows.

The single line of each test case contains one positive integer $n$ ($3 \le n \le 10^5$) — number of tubes in Mike's tubular bells. Also $1 \le l \le r \le 2 \cdot 10^5$, i.e. the lengths of the tubes do not exceed $2 \cdot 10^5$.

It is guaranteed that the sum of maximal number of queries (i.e. $n + 5000$) over all test cases does not exceed $10^5 + 5000$. It means that sum of $n$ does not exceed $10^5 + 5000 - t \cdot 5000$.

Interaction

For each set of input data, read one integer $n$. You are allowed to make no more than $n + 5000$ queries.

If you want to make a query, output it in the format "? $x$ $y$", where $x$ and $y$ — the numbers of tubes for which you learn the lcm (least common multiple) of their lengths. Note that $1 \le x, y \le n, x \neq y$ must be satisfied. The interactor will return a single integer —the answer to your query.

If you are ready to print the answer, print it in the format "! $a_1$ $a_2$ ... $a_n$". The output of the answer is not considered a query and is not included in the number of queries.

After each query and answer output, don't forget to output the line translation and reset the output buffer. Otherwise you will get the verdict "Idleness limit exceeded". To reset the buffer 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.

Note that the interactor is not adaptive. That is, the original permutation is fixed in the beginning and don't depend on your queries.

Example

Input

```
3
5
8 10 7 6 9
5
24 25 28 27 26
7
1 2 3 4 5 6 7
```

Output

```
? 1 2
40
? 2 5
90
? 3 1
56
? 4 5
18
! 8 10 7 6 9
? 1 5
312
? 2 4
675
! 24 25 28 27 26
? 1 4
4
? 2 5
10
? 3 7
21
? 6 2
6
? 2 5
10
? 1 2
2
? 1 2
2
? 1 2
2
? 1 2
2
? 1 2
2
! 1 2 3 4 5 6 7
```

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

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

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

    }
}

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

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

static bool readLongLong(long long& x) {
    if (!(cin >> x)) return false;
    return true;
}

static long long lcm_ll(long long a, long long b) {
    long long g = std::gcd(a, b);
    return (a / g) * b;
}

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

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

    int t = 0;
    try {
        t = inf.readInt(1, 20, "t");
    } catch (...) {
        query_limit = 0;
        log_metrics();
        finish(_fail, "Invalid hidden input (t).");
    }

    vector<int> ns(t);
    vector<vector<int>> a(t);

    long long total_limit = 0;
    try {
        for (int tc = 0; tc < t; tc++) {
            int n = inf.readInt(3, 100000, "n");
            ns[tc] = n;
            a[tc].resize(n);
            for (int i = 0; i < n; i++) {
                a[tc][i] = inf.readInt(1, 200000, "a_i");
            }
            total_limit += (long long)n + 5000LL;
        }
    } catch (...) {
        query_limit = 0;
        log_metrics();
        finish(_fail, "Invalid hidden input (test data).");
    }

    query_limit = total_limit;

    log_metrics();

    cout << t << "\n" << flush;

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

    for (int tc = 0; tc < t; tc++) {
        int n = ns[tc];
        const vector<int>& perm = a[tc];

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

        while (true) {
            string cmd;
            if (!readToken(cmd)) {
                finish(_wa, "Unexpected EOF from contestant.");
            }

            if (cmd == "?") {
                long long x, y;
                if (!readLongLong(x) || !readLongLong(y)) {
                    finish(_pe, "Malformed query arguments.");
                }
                if (x < 1 || x > n || y < 1 || y > n || x == y) {
                    finish(_pe, "Query indices out of range or equal.");
                }

                queries++;
                if (queries > hard_cap) {
                    finish(_pe, "Hard cap on number of queries exceeded.");
                }

                long long ax = perm[(int)x - 1];
                long long ay = perm[(int)y - 1];
                long long ans = lcm_ll(ax, ay);

                cout << ans << "\n" << flush;
            } else if (cmd == "!") {
                vector<int> out(n);
                for (int i = 0; i < n; i++) {
                    long long v;
                    if (!readLongLong(v)) finish(_pe, "Malformed answer: not enough integers.");
                    if (v < INT_MIN || v > INT_MAX) finish(_pe, "Malformed answer: integer out of 32-bit range.");
                    out[i] = (int)v;
                }

                if (out != perm) {

                    int bad = -1;
                    for (int i = 0; i < n; i++) if (out[i] != perm[i]) { bad = i; break; }
                    if (bad == -1) bad = 0;
                    finish(_wa, "Wrong permutation.");
                }

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

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

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

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

static void placeValue(vector<int>& a, int value, int pos) {
    int n = (int)a.size();
    if (pos < 0 || pos >= n) return;
    int idx = -1;
    for (int i = 0; i < n; i++) if (a[i] == value) { idx = i; break; }
    if (idx == -1) return;
    swap(a[idx], a[pos]);
}

static vector<int> buildPermutation(int n, int l, int forcedPattern ) {
    int r = l + n - 1;
    vector<int> base(n);
    for (int i = 0; i < n; i++) base[i] = l + i;

    int pat = forcedPattern;
    if (pat < 0) pat = rnd.next(0, 3);

    vector<int> a;
    if (pat == 0) {
        a = base;
        fisherYatesShuffle(a);
    } else if (pat == 1) {
        a = base;
        reverse(a.begin(), a.end());

        int blk = max(50, min(400, n / 200));
        for (int start = 0; start < n; start += blk) {
            int end = min(n, start + blk);
            int swaps = min(30, end - start);
            for (int it = 0; it < swaps; it++) {
                int i = rnd.next(start, end - 1);
                int j = rnd.next(start, end - 1);
                if (i != j) swap(a[i], a[j]);
            }
        }
    } else if (pat == 2) {

        a.reserve(n);
        int lo = l, hi = r;
        for (int k = 0; k < n; k++) {
            if ((k & 1) == 0) a.push_back(lo++);
            else a.push_back(hi--);
        }

        int off = rnd.next(0, n - 1);
        rotate(a.begin(), a.begin() + off, a.end());
    } else {

        int baseG = 180180;
        vector<pair<int,int>> v;
        v.reserve(n);
        for (int x : base) {
            int g = std::gcd(x, baseG);
            v.push_back({-g, x});
        }
        sort(v.begin(), v.end());
        a.resize(n);
        for (int i = 0; i < n; i++) a[i] = v[i].second;

        int i = 0;
        while (i < n) {
            int j = i;
            while (j < n && v[j].first == v[i].first) j++;
            for (int k = j - 1; k > i; --k) {
                int t = rnd.next(i, k);
                swap(a[k], a[t]);
            }
            i = j;
        }
    }

    if (n >= 3) {
        int posR = n / 2;
        int posL = n / 7;
        int posR1 = n - 1 - n / 9;
        if (posR == posL) posL = (posL + 1) % n;
        if (posR1 == posR) posR1 = (posR1 + 1) % n;
        if (posR1 == posL) posR1 = (posR1 + 2) % n;

        placeValue(a, r, posR);
        placeValue(a, l, posL);
        placeValue(a, r - 1, posR1);

        int pref = min(n, 2000);
        for (int it = 0; it < min(500, pref); it++) {
            int i1 = rnd.next(0, pref - 1);
            int i2 = rnd.next(0, pref - 1);
            if (i1 != i2) swap(a[i1], a[i2]);
        }
    }

    return a;
}

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

    string mode = opt<string>("mode", "non");
    long long seed = atoll(argv[1]);

    int nOpt = opt<int>("n", -1);
    int lOpt = opt<int>("l", -1);
    int patOpt = opt<int>("pattern", -1);

    int n, l;

    if (seed == 1) {
        n = 3;
        l = 1;
    } else if (seed == 2) {
        n = 3;
        l = 199998;
    } else if (seed == 3) {
        n = 100000;
        l = 100001;
    } else {
        n = (nOpt != -1 ? nOpt : (100000 - rnd.next(0, 3000)));
        n = max(n, 3);
        int maxL = 200000 - n + 1;
        if (maxL < 1) {
            n = 100000;
            maxL = 200000 - n + 1;
        }
        if (lOpt != -1) {
            l = lOpt;
        } else {
            int roll = rnd.next(0, 99);
            if (roll < 75) l = maxL;
            else if (roll < 90) l = rnd.next(1, maxL);
            else l = 1;
        }
    }

    if (nOpt != -1) n = nOpt;
    n = max(n, 3);
    int maxL = 200000 - n + 1;
    if (maxL < 1) { n = 3; maxL = 200000 - n + 1; }
    if (lOpt != -1) l = lOpt;
    l = min(max(l, 1), maxL);

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

    cout << 1 << "\n";

    if (mode == "adp") {

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

    cout << n << "\n";
    int forcedPattern = patOpt;
    if (seed == 3 && patOpt == -1) forcedPattern = 3;
    vector<int> a = buildPermutation(n, l, forcedPattern);

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


This is an interactive problem. This means that the input to your program will change based on what your program outputs.

Väinö has been selected as the new chairman for the Iconic Character Poetry Contest (ICPC), a televised battle of wits and verse boasting the nation’s best and brightest. Unfortunately, ICPC’s popularity has exploded in recent years, and Väinö is beset with hoards of new applicants wishing to test their mettle.

The program has a limited number of slots to accept applicants, and Väinö is tasked with ensuring that only the best applicants get said slots. He has decided to host a qualifying tournament to decide who advances. In the tournament, he will invite two applicants at a time to compete with each other to assess which has the greater skill at poetry, or runous. He is certain that no two applicants will have the same skill level. The skill levels are transitive, so if $\exists$ defeats b and b defeats $\subset$ , then $\exists$ would also defeat $\subset$ .

However, his time is limited and he wants to limit how many matches he must hold in order to determine the top applicants that will advance. Can you help him choose which matches to hold?

# Interaction

Interaction begins by reading two integers, $N$ and $K$ , representing the total number of applicants and the number that will advance. You are given that $1 \leq N \leq 1 5 0 0 0$ and $1 \le K \le \operatorname* { m i n } ( N , 3 0 )$ . The $N$ applicants are numbered from 1 to $N$ .

You may then make at most $1 2 N + 1 0 0 0$ queries of the form $? \ \mathrm { ~ a ~ } \ \mathrm { ~ b ~ }$ , where $1 \leq a , b \leq N$ and $a \neq b$ . This represents holding a match between applicants $a$ and $b$ , and the interactor will respond with either $a$ or $b$ , representing which applicant won the match and has higher skill.

Remember to flush your output after making a query.

cout.flush(); // $\mathrm { C } + +$ System.out.flush(); // Java print(..., flush ${ . } = { }$ True) # Python

Your submission will receive a Wrong Answer verdict if you make more than $1 2 N + 1 0 0 0$ queries.

Once you have identified the $K$ applicants with highest skill, print them out in the form ! $_ { \textrm { x l } }$ $_ { \textrm { x 2 } }$ x3 ... xK. The top $K$ applicants may be output in any order. Your program should then exit.

The interactor is not adaptive, meaning that the skill level of each applicant is predetermined at the start of the interaction and does not change during the interaction.

Beyond correctly identifying the top $K$ applicants, your queries must also show that your answer is the unique set of $K$ applicants that could be the top $K$ — Väinö’s wrath will befall you if there is any possibility of you missing a budding talent! For example, simply outputting $\ ! 5 3 4$ for the sample will receive Wrong Answer since your queries have not proven that $\{ 5 , 3 , 4 \}$ are the top 3 applicants.

If the interactor receives any invalid input, the interactor will output $- 1$ and then immediately terminate. Your program should cleanly exit in order to receive a Wrong Answer verdict, otherwise the verdict that it receives may be an arbitrary verdict indicating that your submission is incorrect.

You are provided with a command-line tool for local testing. The tool has comments at the top to explain its use.

Read                                         Sample Interaction 1                                         Write63

63

	？13

3

	？12

1

	？35

5

	？36

3

	？54

5

	？34

4

	！534

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

using namespace std;

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

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

template <typename... Args>
static void finish(TResult verdict, const char* fmt, Args... args) {
    log_metrics();
    quitf(verdict, fmt, args...);
}

const int MAXN = 15005;
int skills[MAXN];
vector<int> adj[MAXN];
int in_degree[MAXN];
bitset<MAXN> anc[MAXN];

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

    int n = inf.readInt(1, 15000, "n");
    int k = inf.readInt(1, min(n, 30), "k");

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

    query_limit = 12LL * n + 1000;

    long long hard_cap = std::max((long long)200000, 2 * query_limit);

    log_metrics();

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

    string token;
    while (true) {

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

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

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

        if (token == "?") {
            int u, v;
            if (!(cin >> u >> v)) {
                finish(_wa, "Invalid query format: expected two integers");
            }

            if (u < 1 || u > n || v < 1 || v > n || u == v) {
                cout << -1 << endl;
                finish(_wa, "Invalid query arguments: %d %d", u, v);
            }

            queries++;

            int winner;
            if (skills[u] > skills[v]) {
                winner = u;
                adj[u].push_back(v);
                in_degree[v]++;
            } else {
                winner = v;
                adj[v].push_back(u);
                in_degree[u]++;
            }

            cout << winner << endl;
        } else if (token == "!") {

            vector<int> ans;
            set<int> distinct_ans;
            for (int i = 0; i < k; i++) {
                int x;
                if (!(cin >> x)) {
                    finish(_wa, "Invalid answer format: expected K integers");
                }
                if (x < 1 || x > n) {
                    finish(_wa, "Answer index out of range: %d", x);
                }
                ans.push_back(x);
                distinct_ans.insert(x);
            }

            if (distinct_ans.size() != k) {
                finish(_wa, "Answer contains duplicate indices");
            }

            vector<pair<int, int>> sorted_skills;
            for (int i = 1; i <= n; i++) {
                sorted_skills.push_back({skills[i], i});
            }
            sort(sorted_skills.rbegin(), sorted_skills.rend());

            set<int> true_top_k;
            for (int i = 0; i < k; i++) {
                true_top_k.insert(sorted_skills[i].second);
            }

            if (distinct_ans != true_top_k) {
                finish(_wa, "Incorrect set of applicants (not the actual top K)");
            }

            vector<int> q;
            int current_in[MAXN];
            for (int i = 1; i <= n; i++) current_in[i] = in_degree[i];

            for (int i = 1; i <= n; i++) {
                if (current_in[i] == 0) q.push_back(i);
            }

            int head = 0;
            while(head < (int)q.size()) {
                int u = q[head++];

                for (int v : adj[u]) {

                    anc[v] |= anc[u];
                    anc[v].set(u);

                    current_in[v]--;
                    if (current_in[v] == 0) {
                        q.push_back(v);
                    }
                }
            }

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

                if (distinct_ans.find(i) == distinct_ans.end()) {
                    if ((int)anc[i].count() < k) {
                        finish(_wa, "Uniqueness not proven: candidate %d has only %d known superiors (need %d)", i, (int)anc[i].count(), k);
                    }
                }
            }

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

            finish(_ok, "Correct and proven");

        } else {

            cout << -1 << endl;
            finish(_wa, "Invalid protocol token: '%s'", token.c_str());
        }
    }

    return 0;
}

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

using namespace std;

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

    registerGen(argc, argv, 1);

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

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

    if (n == -1) {
        if (seed_val == 1) {
            n = 2; k = 1;
        } else if (seed_val == 2) {
            n = 15000; k = 30;
        } else if (seed_val == 3) {
            n = 15000; k = 1;
        } else if (seed_val == 4) {
            n = 30; k = 30;
        } else if (seed_val == 5) {
            n = 60; k = 30;
        } else if (seed_val == 6) {
            n = 100; k = 10;
        } else {

            int type = rnd.next(100);
            if (type < 5) n = rnd.next(2, 50);
            else if (type < 15) n = rnd.next(50, 1000);
            else n = rnd.next(1000, 15000);
        }
    }

    if (k == -1) {
        int max_k = min(n, 30);

        int type = rnd.next(10);
        if (type == 0) k = 1;
        else if (type == 1) k = max_k;
        else k = rnd.next(1, max_k);
    }

    n = max(1, min(15000, n));
    k = max(1, min(min(n, 30), k));

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

    if (mode == "non") {
        vector<int> p(n);
        iota(p.begin(), p.end(), 1);

        bool special = false;

        if (seed_val == 7) {

            special = true;
        } else if (seed_val == 8) {

            reverse(p.begin(), p.end());
            special = true;
        }

        if (!special) {

            if (rnd.next(20) == 0) {

                int swaps = rnd.next(1, max(1, n / 20));
                for (int i = 0; i < swaps; i++) {
                    int a = rnd.next(n);
                    int b = rnd.next(n);
                    swap(p[a], p[b]);
                }
            } else {

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

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

    return 0;
}


### Problem Statement

There is a tree with $N$ vertices, numbered $1, \ldots, N$.
For each pair of integers $u,v\, (1 \leq u,v \leq N)$, the distance $d_{u,v}$ between Vertices $u, v$ is defined as the following.

* The number of edges contained in the shortest path connecting Vertices $u$ and $v$.

You are allowed to ask between $0$ and $2N$ questions (inclusive) in the following form.

* Ask the distance $d_{u,v}$ between Vertices $u,v$ for integers $u,v$ of your choice such that $1\leq u,v \leq N$ and $u+v>3$.

Find the distance $d_{1,2}$ between Vertices $1,2$.

### Constraints

* $3 \leq N \leq 100$
* $N$ is an integer.
* The tree is determined before the start of the interaction between your program and the judge.

### Input and Output

**This is an interactive task**, in which your program and the judge interact via input and output.

First, your program is given a positive integer $N$ from Standard Input:

```
$N$
```

Then, you get to ask questions.
A question should be printed in the following format (with a newline at the end):

```
? $u$ $v$
```

If the question is valid, the response $d_{u,v}$ is given from Standard Input:

```
$d_{u,v}$
```

If the question is judged invalid because, for example, it is malformed or you have asked too many questions, you get `-1` instead of the response:

```
-1
```

At this point, your submission is already judged incorrect. The judge's program then terminates; yours should too, desirably.

When you find the answer $d_{1,2}$, print it to Standard Output in the following format (with a newline at the end):

```
! $d_{1,2}$
```

### Notices

* **Flush Standard Output after each output. Otherwise, you might get the TLE verdict.**
* After printing the answer (or receiving `-1`), immediately terminate the program normally. Otherwise, the verdict would be indeterminate.
* The verdict for the case of a malformed output would be indeterminate.
* Specifically, note that too many newlines would also be seen as a malformed output.

---

### Sample Input and Output

The following is a sample interaction for the tree shown in this image.

![](https://img.atcoder.jp/arc142/1435f0bc323a9e21cf3abf1c4911e826.png)

| Input | Output | Description |
| --- | --- | --- |
| `3` |  | Interaction starts with the integer $N$. |
|  | `?` `1` `3` | As the $1$-st question, you ask the distance between Vertices $1$ and $3$. |
| `1` |  | The distance between Vertices $1,3$ is returned. |
|  | `?` `2` `2` | As the $2$-nd question, you ask the distance between Vertices $2$ and $2$. |
| `0` |  | The distance between Vertices $2,2$ is returned. |
|  | `?` `2` `3` | As the $3$-rd question, you ask the distance between Vertices $2$ and $3$. |
| `1` |  | The distance between Vertices $2,3$ is returned. |
|  | `?` `3` `1` | As the $4$-th question, you ask the distance between Vertices $3$ and $1$. |
| `1` |  | The distance between Vertices $3,1$ is returned. |
|  | `?` `3` `2` | As the $5$-th question, you ask the distance between Vertices $3$ and $2$. |
| `1` |  | The distance between Vertices $3,2$ is returned. |
|  | `?` `2` `2` | As the $6$-th question, you ask the distance between Vertices $2$ and $2$. |
| `0` |  | The distance between Vertices $2,2$ is returned. |
|  | `!` `2` | You guess the distance between Vertices $1,2$ and terminate. The actual distance between them is $2$, so you would get the AC verdict. |

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

using namespace std;

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

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

    }
}

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

const int MAXN = 105;
const int INF = 1e9;
int dist_mat[MAXN][MAXN];
int N;

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

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

    N = inf.readInt();
    query_limit = 2 * N;

    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            dist_mat[i][j] = (i == j) ? 0 : INF;
        }
    }

    for (int i = 0; i < N - 1; ++i) {
        int u = inf.readInt();
        int v = inf.readInt();
        if (u >= 1 && u <= N && v >= 1 && v <= N) {
            dist_mat[u][v] = 1;
            dist_mat[v][u] = 1;
        }
    }

    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                if (dist_mat[i][k] != INF && dist_mat[k][j] != INF) {
                    dist_mat[i][j] = min(dist_mat[i][j], dist_mat[i][k] + dist_mat[k][j]);
                }
            }
        }
    }

    cout << N << endl;

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

    while (true) {

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

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

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

        if (token == "!") {

            int ans;
            if (!(cin >> ans)) {
                finish(_wa, "Malformed answer (expected integer after '!')");
            }

            int expected = dist_mat[1][2];
            if (ans == expected) {
                finish(_ok, format("Correct! Distance is %d", expected));
            } else {
                finish(_wa, format("Wrong answer. Expected %d, found %d", expected, ans));
            }

        } else {

            int u, v;
            if (token == "?") {
                if (!(cin >> u >> v)) {
                    finish(_wa, "Malformed query (expected 'u v' after '?')");
                }
            } else {

                try {
                    size_t pos;
                    u = stoi(token, &pos);
                    if (pos != token.size()) throw exception();
                } catch (...) {
                    finish(_wa, "Invalid token '" + token + "' (expected '?', '!' or integer)");
                }
                if (!(cin >> v)) {
                    finish(_wa, "Malformed query (expected 'v' after 'u')");
                }
            }

            bool range_ok = (u >= 1 && u <= N && v >= 1 && v <= N);

            bool condition_ok = (u + v > 3);

            if (!range_ok) {
                cout << "-1" << endl;
                finish(_wa, format("Invalid query vertices (%d, %d) out of range [1, %d]", u, v, N));
            }
            if (!condition_ok) {
                cout << "-1" << endl;
                finish(_wa, format("Invalid query vertices (%d, %d): sum must be > 3", u, v));
            }

            queries++;
            if (queries > query_limit) {
                cout << "-1" << endl;
                finish(_wa, format("Query limit exceeded (%d > %d)", queries, query_limit));
            }

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

            cout << dist_mat[u][v] << 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");
    int N = opt<int>("N", -1);

    if (N == -1) {

        if (rnd.next(100) < 15) {
            N = rnd.next(3, 10);
        } else {
            N = rnd.next(11, 100);
        }
    }

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

    cout << N << endl;

    int type = rnd.next(8);

    if (N == 3) {

        if (type == 3) type = 2;
        if (type == 1) type = 6;
    } else if (N == 4) {

    }

    vector<pair<int,int>> edges;

    if (type == 0) {

        vector<int> p(N);
        iota(p.begin(), p.end(), 1);
        shuffle(p.begin(), p.end());
        for (int i = 1; i < N; i++) {
            edges.push_back({p[i], p[rnd.next(i)]});
        }
    } else if (type == 1) {

        vector<int> mid;
        for(int i = 3; i <= N; i++) mid.push_back(i);
        shuffle(mid.begin(), mid.end());
        int u = 1;
        for (int v : mid) {
            edges.push_back({u, v});
            u = v;
        }
        edges.push_back({u, 2});
    } else if (type == 2) {

        edges.push_back({1, 2});
        vector<int> in_tree = {1, 2};
        vector<int> others;
        for(int i = 3; i <= N; i++) others.push_back(i);
        shuffle(others.begin(), others.end());
        for (int v : others) {
            edges.push_back({v, in_tree[rnd.next(in_tree.size())]});
            in_tree.push_back(v);
        }
    } else if (type == 3) {

        if (N >= 4) {
            vector<int> others;
            for(int i = 3; i <= N; i++) others.push_back(i);
            shuffle(others.begin(), others.end());
            int a = others.back(); others.pop_back();
            int b = others.back(); others.pop_back();
            edges.push_back({1, a});
            edges.push_back({a, b});
            edges.push_back({b, 2});
            vector<int> in_tree = {1, 2, a, b};
            for (int v : others) {
                edges.push_back({v, in_tree[rnd.next(in_tree.size())]});
                in_tree.push_back(v);
            }
        } else {

            edges.push_back({1, 3});
            edges.push_back({3, 2});
        }
    } else if (type == 4) {

        for (int i = 2; i <= N; i++) edges.push_back({1, i});
    } else if (type == 5) {

        for (int i = 1; i <= N; i++) if (i != 2) edges.push_back({2, i});
    } else if (type == 6) {

        int c = rnd.next(3, N);
        for (int i = 1; i <= N; i++) if (i != c) edges.push_back({c, i});
    } else if (type == 7) {

        vector<int> others;
        for(int i = 3; i <= N; i++) others.push_back(i);
        shuffle(others.begin(), others.end());

        int nodes_on_path = rnd.next(0, (int)others.size());

        if (nodes_on_path == 0) {

            edges.push_back({1, 2});
            vector<int> in_tree = {1, 2};
            for (int v : others) {
                edges.push_back({v, in_tree[rnd.next(in_tree.size())]});
                in_tree.push_back(v);
            }
        } else {
            int u = 1;
            vector<int> in_tree = {1};
            for (int i = 0; i < nodes_on_path; i++) {
                int v = others[i];
                edges.push_back({u, v});
                in_tree.push_back(v);
                u = v;
            }
            edges.push_back({u, 2});
            in_tree.push_back(2);

            for (size_t i = nodes_on_path; i < others.size(); i++) {
                int v = others[i];
                edges.push_back({v, in_tree[rnd.next(in_tree.size())]});
                in_tree.push_back(v);
            }
        }
    }

    vector<int> p(N + 1);
    p[1] = 1;
    p[2] = 2;
    vector<int> perm;
    for (int i = 3; i <= N; i++) perm.push_back(i);
    shuffle(perm.begin(), perm.end());
    for (int i = 0; i < (int)perm.size(); i++) {
        p[3 + i] = perm[i];
    }

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

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

    return 0;
}