Problem: cf1562_f
Difficulty: medium
Categories: math
Time limit: 5000 ms, memory limit: 512 MB

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
```

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


Adaptive interactor (C++):

Test generator (C++):
#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;
}