Problem: cf1815_b
Difficulty: medium
Categories: graph
Time limit: 3000 ms, memory limit: 256 MB

This is an interactive problem.

There is a hidden permutation $p_1, p_2, \dots, p_n$.

Consider an undirected graph with $n$ nodes only with no edges. You can make two types of queries:

1. Specify an integer $x$ satisfying $2 \le x \le 2n$. For all integers $i$ ($1 \le i \le n$) such that $1 \le x-i \le n$, an edge between node $i$ and node $x-i$ will be added.
2. Query the number of edges in the shortest path between node $p_i$ and node $p_j$. As the answer to this question you will get the number of edges in the shortest path if such a path exists, or $-1$ if there is no such path.

Note that you can make both types of queries in any order.

Within $2n$ queries (including type $1$ and type $2$), guess two possible permutations, at least one of which is $p_1, p_2, \dots, p_n$. You get accepted if at least one of the permutations is correct. You are allowed to guess the same permutation twice.

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

Input

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

The first line of each test case contains a single integer $n$ ($2 \le n \le 10^3$) — the length of the permutation.

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

Interaction

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

Then, make at most $2n$ queries:

* If you want to make a type $1$ query, output "+ x". $x$ must be an integer between $2$ and $2n$ inclusive. After doing that read $1$ or $-2$. If you read $1$ your query was valid, otherwise it was invalid or you exceed the limit of queries, and your program must terminate immediately to receive a Wrong Answer verdict.
* If you want to make a type $2$ query, output "? i j". $i$ and $j$ must be integers between $1$ and $n$ inclusive. After that, read in a single integer $r$ ($-1 \le r \le n$) — the answer to your query. If you receive the integer $−2$ instead of an answer, it means your program has made an invalid query, or has exceeded the limit of queries. Your program must terminate immediately to receive a Wrong Answer verdict.

At any point of the interaction, if you want to guess two permutations, output "! $p_{1,1}$ $p_{1,2}$ $\dots$ $p_{1,n}$ $p_{2,1}$ $p_{2,2}$ $\dots$ $p_{2,n}$". Note that you should output the two permutations on the same line, and no exclamation mark is needed to separate the two permutations. After doing that read $1$ or $-2$. If you read $1$ your answer was correct, otherwise it was incorrect and your program must terminate immediately to receive a Wrong Answer verdict. After that, move on to the next test case, or terminate the program if there are none. Note that reporting the answer does not count as a query.

Note that even if you output a correct permutation, the second permutation should be a permutation and not an arbitrary array.

At any point, if you continue interaction after reading in the integer $-2$, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

After printing a query or the answer do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

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

Interactor is non-adaptive. This means that all permutations are fixed before the interaction starts.

Example

Input

```
2
6

1

1

1

1

1

2

-1

1
2

1
```

Output

```
+ 12

+ 2

+ 3

? 1 3

+ 5

? 1 5

? 4 5

! 1 4 2 5 3 6 1 2 3 4 5 6

! 1 2 2 1
```

Note

In the first test case, $n=6$ and the hidden permutation $p = [1,4,2,5,3,6]$.

Firstly, make a type $1$ query on $x=12, 2, 3$ respectively. This adds four edges to the graph in total:

* An edge that connects node $6$ and node $6$.
* An edge that connects node $1$ and node $1$.
* An edge that connects node $1$ and node $2$.
* An edge that connects node $2$ and node $1$.

Since all of these queries are valid, the interactor returns $1$ after each of them.

Then, query the number of edges in the shortest path between node $p_1 = 1$ and $p_3 = 2$, which is equal to $1$.

Then, make a type $1$ query on $x=5$. This adds four edges to the graph in total:

* An edge that connects node $1$ and node $4$.
* An edge that connects node $2$ and node $3$.
* An edge that connects node $3$ and node $2$.
* An edge that connects node $4$ and node $1$.

Since this query is valid, the interactor returns $1$.

Then, query the number of edges in the shortest path between node $p_1 = 1$ and $p_5 = 3$, which is equal to $2$.

Then, query the number of edges in the shortest path between node $p_4 = 5$ and $p_5 = 3$. Such a path doesn't exist, therefore the interactor returns $-1$.

Afterwards, due to some magic, two possible permutations that can be $p$ are determined: the first permutation is $[1,4,2,5,3,6]$ and the second permutation is $[1,2,3,4,5,6]$. Since the first permutation is equal to the hidden permutation, this test case is solved correctly. In total, $7$ queries are used, which is within the limit of $2 \cdot 6 = 12$ queries.

Since the answer is correct, the interactor returns $1$.

In the second test case, $n=2$ and the hidden permutation is $p = [2,1]$.

Since there are only $2! = 2$ possible permutations, no queries are needed. It is sufficient to just output the two permutations, $[1,2]$ and $[2,1]$. In total, $0$ queries are used, which is within the limit of $2 \cdot 2 = 4$ queries.

Since the answer is correct, the interactor returns $1$.

Non-adaptive interactor (C++):
#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 && queries == 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 t = inf.readInt();
    
    cout << t << endl;

    while (t--) {
        int n = inf.readInt();
        
        query_limit += 2 * n;

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

        
        cout << n << endl;

        
        
        vector<vector<int>> adj(n + 1);
        vector<vector<bool>> has_edge(n + 1, vector<bool>(n + 1, false));

        bool solved = false;
        while (!solved) {
            
            
            if (queries > 200000) {
                finish(_pe, "Hard query limit exceeded (200000)");
            }

            string token;
            
            if (!(cin >> token)) {
                finish(_wa, "Unexpected end of input from solution");
            }

            if (token == "+") {
                
                int x;
                if (!(cin >> x)) finish(_wa, "Expected integer x after '+'");
                
                queries++;

                
                if (x < 2 || x > 2 * n) {
                    finish(_wa, format("x=%d out of range [2, %d]", x, 2 * n));
                }

                
                
                for (int i = 1; i <= n; ++i) {
                    int j = x - i;
                    if (j >= 1 && j <= n) {
                        
                        if (!has_edge[i][j]) {
                            has_edge[i][j] = true;
                            has_edge[j][i] = true;
                            adj[i].push_back(j);
                            adj[j].push_back(i);
                        }
                    }
                }
                
                cout << 1 << endl;

            } else if (token == "?") {
                
                int i, j;
                if (!(cin >> i >> j)) finish(_wa, "Expected integers i j after '?'");
                
                queries++;

                
                if (i < 1 || i > n || j < 1 || j > n) {
                    finish(_wa, format("Indices (%d, %d) out of range [1, %d]", i, j, n));
                }

                int u = p[i - 1];
                int v = p[j - 1];

                if (u == v) {
                    
                    cout << 0 << endl;
                } else {
                    
                    queue<pair<int, int>> q;
                    q.push({u, 0});
                    
                    vector<int> dist(n + 1, -1);
                    dist[u] = 0;
                    
                    int result = -1;
                    while (!q.empty()) {
                        auto [curr, d] = q.front();
                        q.pop();

                        if (curr == v) {
                            result = d;
                            break;
                        }

                        for (int neighbor : adj[curr]) {
                            if (dist[neighbor] == -1) {
                                dist[neighbor] = d + 1;
                                q.push({neighbor, d + 1});
                            }
                        }
                    }
                    cout << result << endl;
                }

            } else if (token == "!") {
                
                
                
                vector<int> guess1(n), guess2(n);
                
                
                auto read_and_validate = [&](vector<int>& out_vec) -> bool {
                    vector<bool> seen(n + 1, false);
                    for (int k = 0; k < n; ++k) {
                        if (!(cin >> out_vec[k])) return false;
                        if (out_vec[k] < 1 || out_vec[k] > n) return false;
                        if (seen[out_vec[k]]) return false;
                        seen[out_vec[k]] = true;
                    }
                    return true;
                };

                if (!read_and_validate(guess1)) finish(_wa, "Invalid permutation format (guess 1)");
                if (!read_and_validate(guess2)) finish(_wa, "Invalid permutation format (guess 2)");

                
                bool match1 = (guess1 == p);
                bool match2 = (guess2 == p);

                if (match1 || match2) {
                    cout << 1 << endl;
                    solved = true; 
                } else {
                    finish(_wa, "Neither guessed permutation is correct");
                }

            } else {
                finish(_wa, format("Unknown query token '%s'", token.c_str()));
            }
        }
    }

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


Adaptive interactor (C++):

Test generator (C++):
#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 = -1;
    try {
        if (argc > 1) seed_val = stoi(argv[1]);
    } catch (...) {
        seed_val = -1;
    }

    const int MAX_SUM = 1000;
    const int MAX_T = 100;
    vector<int> ns;

    if (seed_val == 1) {
        
        ns.push_back(MAX_SUM);
    } else if (seed_val == 2) {
        
        int current_sum = 0;
        while (current_sum + 2 <= MAX_SUM && ns.size() < MAX_T) {
            ns.push_back(2);
            current_sum += 2;
        }
    } else if (seed_val == 3) {
        
        int current_sum = 0;
        while (current_sum + 2 <= MAX_SUM && ns.size() < MAX_T) {
            int rem = MAX_SUM - current_sum;
            
            int n = rnd.next(2, min(rem, 20));
            
            
            if (rem - n == 1) n++;
            
            ns.push_back(n);
            current_sum += n;
        }
    } else {
        
        int type = rnd.next(3);
        
        if (type == 0) {
            
            ns.push_back(MAX_SUM);
        } else {
            
            
            int limit_upper = (type == 1) ? 200 : 50;
            int current_sum = 0;
            
            while (current_sum + 2 <= MAX_SUM && ns.size() < MAX_T) {
                int rem = MAX_SUM - current_sum;
                int n = rnd.next(2, min(rem, limit_upper));
                
                
                if (rem - n == 1) n++;
                
                ns.push_back(n);
                current_sum += n;
            }
            
            
            
            
        }
    }

    
    cout << ns.size() << endl;
    for (int n : ns) {
        cout << n << endl;
        if (mode == "non") {
            
            vector<int> p(n);
            iota(p.begin(), p.end(), 1);
            shuffle(p.begin(), p.end());
            for (int i = 0; i < n; i++) {
                cout << p[i] << (i == n - 1 ? "" : " ");
            }
            cout << endl;
        }
        
    }

    return 0;
}