Problem: cf2129_f1
Difficulty: medium
Categories: bit
Time limit: 3000 ms, memory limit: 256 MB

This is an interactive problem.

This is the easy version of the problem. The only difference is that $n \le 845$ in this version. 

There is a hidden permutation $p$, which is a permutation of $\{1,2,\ldots,n\}$. Let $pos_i$ denote the position of the value $i$ in $p$, i.e., $pos_{p_i} = i$.

To find this permutation, you can ask four types of queries:

* "$1\ m\ i_1\ i_2\ \ldots\ i_m$" ($1 \leq m \leq n$, $i_1,\ i_2,\ \ldots,\ i_m$ must be distinct). Let $k = \min(60, m)$. The jury will return the top $k$ largest number(s) in $[p_{i_1}, p_{i_2}, \ldots, p_{i_m}]$ in increasing order.
* "$2\ m\ i_1\ i_2\ \ldots\ i_m$" ($1 \leq m \leq n$, $i_1,\ i_2,\ \ldots,\ i_m$ must be distinct). Let $k = \min(60, m)$. The jury will return the top $k$ largest number(s) in $[pos_{i_1}, pos_{i_2}, \ldots, pos_{i_m}]$ in increasing order.
* "$3\ m\ i_1\ i_2\ ...\ i_m$" ($1 \leq m \leq n$, $i_1,\ i_2,\ ...,\ i_m$ must be distinct). Let $k = \min(300, m)$. The jury will return the top $k$ largest number(s) in $[p_{i_1}, p_{i_2}, ..., p_{i_m}]$ in increasing order.
* "$4\ m\ i_1\ i_2\ \ldots\ i_m$" ($1 \leq m \leq n$, $i_1,\ i_2,\ \ldots,\ i_m$ must be distinct). Let $k = \min(300, m)$. The jury will return the top $k$ largest number(s) in $[pos_{i_1}, pos_{i_2}, \ldots, pos_{i_m}]$ in increasing order.

Let $c_i$ be the usage count of queries of type $i$ $(1 \le i \le 4)$. Your query count must satisfy the following constraints:

* $c_1+c_2+c_3+c_4 \le 30.$
* $c_3+c_4 \le 1.$

Input

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

Interaction

The first line of each test case contains one integer $n$ ($2 \le n \le 845$). At this moment, the permutation $p$ is chosen. The interactor in this task is not adaptive. In other words, the permutation $p$ is fixed in every test case and does not change during the interaction.

To ask a query of type $1$, you need to print the line of the following form (without quotes):

* "$1\ m\ i_1\ i_2\ \ldots\ i_m$" ($1 \leq m \leq n$, $i_1, i_2, \ldots, i_m$ must be distinct)

After that, you receive $k=\min(60,m)$ integer(s) — the top $k$ largest number(s) in $[p_{i_1}, p_{i_2}, \ldots, p_{i_m}]$ in increasing order.

To ask a query of type $2$, you need to print the line of the following form (without quotes):

* "$2\ m\ i_1\ i_2\ \ldots\ i_m$" ($1 \leq m \leq n$, $i_1, i_2, \ldots, i_m$ must be distinct)

After that, you receive $k=\min(60,m)$ integer(s) — the top $k$ largest number(s) in $[pos_{i_1}, pos_{i_2}, \ldots, pos_{i_m}]$ in increasing order.

To ask a query of type $3$, you need to print the line of the following form (without quotes):

* "$3\ m\ i_1\ i_2\ \ldots\ i_m$" ($1 \leq m \leq n$, $i_1, i_2, \ldots, i_m$ must be distinct)

After that, you receive $k=\min(300,m)$ integer(s) — the top $k$ largest number(s) in $[p_{i_1}, p_{i_2}, \ldots, p_{i_m}]$ in increasing order.

To ask a query of type $4$, you need to print the line of the following form (without quotes):

* "$4\ m\ i_1\ i_2\ \ldots\ i_m$" ($1 \leq m \leq n$, $i_1, i_2, \ldots, i_m$ must be distinct)

After that, you receive $k=\min(300,m)$ integer(s) — the top $k$ largest number(s) in $[pos_{i_1}, pos_{i_2}, \ldots, pos_{i_m}]$ in increasing order.

Next, if your program has found the permutation $p$, print the line of the following form (without quotes):

* "$!\ p_1\ p_2\ \ldots\ p_n$"

Note that this line is not considered a query and is not taken into account when counting the number of queries asked.

After this, proceed to the next test case.

After printing a query or the answer for a test case, do not forget to output the end of the line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:

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

Example

Input

```
2
3

2 3

3

2

2
```

Output

```
3 2 3 1

2 1 2

! 3 1 2

4 1 1

! 2 1
```

Note

In the first test case, the hidden permutation is $p = [3, 1, 2]$, thus $pos = [2, 3, 1]$.

For the query "3 2 3 1", the jury returns $2$ and $3$ because $2$ and $3$ are the top $k$ largest number(s) in $[p_3, p_1]$, where $k = \min(300, m) = \min(300, 2) = 2$.

For the query "2 1 2", the jury returns $3$ because $3$ is the top $k$ largest number in $[pos_2]$, where $k = \min(60, m) = \min(60, 1) = 1$.

Note that the example is only for understanding the statement and does not guarantee finding the unique permutation $p$.

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 << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {
        
    }
}

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

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

static vector<int> topKIncreasing(const vector<int>& vals, int k) {
    vector<int> v = vals;
    sort(v.begin(), v.end());
    int m = (int)v.size();
    vector<int> ans;
    ans.reserve(k);
    for (int i = m - k; i < m; i++) ans.push_back(v[i]);
    sort(ans.begin(), ans.end());
    return ans;
}

static void writeReply(const vector<int>& ans) {
    for (int i = 0; i < (int)ans.size(); i++) {
        if (i) cout << ' ';
        cout << ans[i];
    }
    cout << "\n";
    cout.flush();
}

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

    int t = 0;
    try {
        t = inf.readInt();
    } catch (...) {
        finish(_pe, "failed to read t from inf");
    }
    if (t < 1 || t > 1000000) finish(_pe, "invalid t in inf");

    query_limit = 30LL * t;
    log_metrics(); 

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

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

    for (int tc = 1; tc <= t; tc++) {
        int n = 0;
        try {
            n = inf.readInt();
        } catch (...) {
            finish(_pe, "failed to read n from inf");
        }
        if (n < 2 || n > 2000000) finish(_pe, "invalid n in inf");

        vector<int> p(n + 1, 0);
        vector<int> pos(n + 1, 0);
        vector<int> seen(n + 1, 0);

        for (int i = 1; i <= n; i++) {
            int x = 0;
            try {
                x = inf.readInt();
            } catch (...) {
                finish(_pe, "failed to read permutation from inf");
            }
            if (x < 1 || x > n) finish(_pe, "permutation value out of range in inf");
            if (seen[x]) finish(_pe, "duplicate permutation value in inf");
            seen[x] = 1;
            p[i] = x;
        }
        for (int i = 1; i <= n; i++) pos[p[i]] = i;

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

        bool answered = false;
        while (!answered) {
            string tok;
            if (!(cin >> tok)) finish(_pe, "unexpected EOF from contestant");

            if (tok == "!") {
                vector<int> ans(n + 1, 0);
                vector<int> used(n + 1, 0);
                for (int i = 1; i <= n; i++) {
                    long long xll = 0;
                    if (!readLL(xll)) finish(_pe, "EOF while reading final answer");
                    if (xll < 1 || xll > n) finish(_wa, "final answer value out of range");
                    int x = (int)xll;
                    if (used[x]) finish(_wa, "final answer is not a permutation");
                    used[x] = 1;
                    ans[i] = x;
                }
                for (int i = 1; i <= n; i++) {
                    if (ans[i] != p[i]) finish(_wa, "wrong permutation");
                }
                answered = true;
                continue;
            }

            if (tok.size() != 1 || tok[0] < '1' || tok[0] > '4') {
                finish(_pe, "invalid command token");
            }
            int type = tok[0] - '0';

            long long mll = 0;
            if (!readLL(mll)) finish(_pe, "EOF while reading m");
            if (mll < 1 || mll > n) finish(_pe, "m out of range");
            int m = (int)mll;

            vector<int> idx;
            idx.reserve(m);
            vector<char> used(n + 1, 0);
            for (int j = 0; j < m; j++) {
                long long ill = 0;
                if (!readLL(ill)) finish(_pe, "EOF while reading indices");
                if (ill < 1 || ill > n) finish(_pe, "index out of range");
                int ii = (int)ill;
                if (used[ii]) finish(_pe, "duplicate index in query");
                used[ii] = 1;
                idx.push_back(ii);
            }

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

            int lim = (type == 1 || type == 2) ? 60 : 300;
            int k = min(lim, m);

            vector<int> vals;
            vals.reserve(m);
            if (type == 1 || type == 3) {
                for (int x : idx) vals.push_back(p[x]);
            } else {
                for (int x : idx) vals.push_back(pos[x]);
            }

            vector<int> reply = topKIncreasing(vals, k);
            writeReply(reply);
        }
    }

    finish(_ok, "all testcases solved");
    return 0;
}


Adaptive interactor (C++):

Test generator (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static vector<int> makeAlternHighLow(int n) {
    vector<int> p;
    p.reserve(n);
    int lo = 1, hi = n;
    while ((int)p.size() < n) {
        if (hi >= lo) p.push_back(hi--);
        if ((int)p.size() < n && lo <= hi) p.push_back(lo++);
    }
    return p;
}

static vector<int> makeBlockScramble(int n, int B) {
    vector<vector<int>> blocks;
    for (int s = 1; s <= n; s += B) {
        int e = min(n, s + B - 1);
        vector<int> block;
        block.reserve(e - s + 1);
        for (int x = s; x <= e; x++) block.push_back(x);
        reverse(block.begin(), block.end());
        blocks.push_back(std::move(block));
    }
    reverse(blocks.begin(), blocks.end());
    vector<int> p;
    p.reserve(n);
    for (auto &b : blocks) for (int x : b) p.push_back(x);
    return p;
}

static vector<int> makeBitReversal(int n) {
    int bits = 0;
    while ((1 << bits) < n) bits++;
    vector<pair<int,int>> v;
    v.reserve(n);
    for (int i = 0; i < n; i++) {
        int x = i, r = 0;
        for (int b = 0; b < bits; b++) {
            r = (r << 1) | (x & 1);
            x >>= 1;
        }
        v.push_back({r, i});
    }
    sort(v.begin(), v.end());
    vector<int> p(n);
    for (int pos = 0; pos < n; pos++) p[pos] = v[pos].second + 1;
    return p;
}

static vector<int> makeModMul(int n) {
    int a;
    while (true) {
        a = rnd.next(1, n - 1);
        if (std::gcd(a, n) == 1) break;
    }
    int b = rnd.next(0, n - 1);
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        long long val = (1LL * a * i + b) % n;
        p[i] = (int)val + 1;
    }
    return p;
}

static vector<int> makeDominators(int n, int D) {
    D = min(D, n);
    vector<int> p(n, 0);

    vector<int> pos = rnd.perm(n); 
    vector<int> domPos(pos.begin(), pos.begin() + D);

    vector<int> domVals;
    domVals.reserve(D);
    for (int x = n - D + 1; x <= n; x++) domVals.push_back(x);
    
    vector<int> ord = rnd.perm(D);
    vector<int> domValsShuf;
    domValsShuf.reserve(D);
    for (int i = 0; i < D; i++) domValsShuf.push_back(domVals[ord[i]]);

    for (int i = 0; i < D; i++) {
        p[domPos[i]] = domValsShuf[i];
    }

    vector<int> restVals;
    restVals.reserve(n - D);
    for (int x = 1; x <= n - D; x++) restVals.push_back(x);

    
    vector<int> remIdx;
    remIdx.reserve(n - D);
    for (int i = 0; i < n; i++) if (p[i] == 0) remIdx.push_back(i);

    int m = (int)remIdx.size();
    int bits = 0;
    while ((1 << bits) < m) bits++;
    vector<pair<int,int>> br;
    br.reserve(m);
    for (int i = 0; i < m; i++) {
        int x = i, r = 0;
        for (int b = 0; b < bits; b++) {
            r = (r << 1) | (x & 1);
            x >>= 1;
        }
        br.push_back({r, i});
    }
    sort(br.begin(), br.end());
    for (int k = 0; k < m; k++) {
        int idx = remIdx[br[k].second];
        p[idx] = restVals[k];
    }

    return p;
}

static void applyRandomSwaps(vector<int> &p, int swaps) {
    int n = (int)p.size();
    for (int t = 0; t < swaps; t++) {
        int i = rnd.next(0, n - 1);
        int j = rnd.next(0, n - 1);
        if (i != j) swap(p[i], p[j]);
    }
}

static bool isPerm1toN(const vector<int> &p) {
    int n = (int)p.size();
    vector<int> seen(n + 1, 0);
    for (int x : p) {
        if (x < 1 || x > n) return false;
        if (seen[x]) return false;
        seen[x] = 1;
    }
    return true;
}

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

    string mode = opt<string>("mode", "non");
    int maxn = opt<int>("maxn", 845);
    int nOpt = opt<int>("n", 0);

    long long seedVal = 0;
    if (argc >= 2) {
        seedVal = atoll(argv[1]);
        if (seedVal < 0) seedVal = -seedVal;
    }

    int n;
    if (nOpt >= 2) n = min(nOpt, maxn);
    else {
        if (seedVal >= 1 && seedVal <= 3) n = maxn;
        else n = rnd.next(800, maxn);
    }
    if (n < 2) n = 2;

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

    
    vector<int> p;

    if (seedVal == 1) {
        n = 2;
        p = {2, 1};
    } else if (seedVal == 2) {
        n = maxn;
        p = makeBlockScramble(n, 60);
        applyRandomSwaps(p, 25);
    } else if (seedVal == 3) {
        n = maxn;
        p = makeDominators(n, 300);
        applyRandomSwaps(p, 10);
    } else {
        int style = (int)(seedVal % 5);
        if (style == 0) {
            p = makeDominators(n, 300);
            applyRandomSwaps(p, rnd.next(5, 25));
        } else if (style == 1) {
            p = makeAlternHighLow(n);
            applyRandomSwaps(p, rnd.next(10, 40));
        } else if (style == 2) {
            int B = rnd.next(55, 65);
            p = makeBlockScramble(n, B);
            applyRandomSwaps(p, rnd.next(10, 35));
        } else if (style == 3) {
            p = makeBitReversal(n);
            applyRandomSwaps(p, rnd.next(10, 35));
        } else {
            p = makeModMul(n);
            applyRandomSwaps(p, rnd.next(10, 35));
        }
    }

    if (!isPerm1toN(p)) {
        
        vector<int> perm0 = rnd.perm(n);
        p.resize(n);
        for (int i = 0; i < n; i++) p[i] = perm0[i] + 1;
    }

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