Problem: cf1491_f
Difficulty: hard
Categories: search, math
Time limit: 1000 ms, memory limit: 256 MB

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.

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

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


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 = 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;
}