Problem: cf1634_d
Difficulty: medium
Categories: math
Time limit: 1000 ms, memory limit: 256 MB

![](https://espresso.codeforces.com/1b3f8506501b8393400b3a441a3b82b3bab2bb30.png) 

This is an interactive problem.

We picked an array of whole numbers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) and concealed exactly one zero in it! Your goal is to find the location of this zero, that is, to find $i$ such that $a_i = 0$.

You are allowed to make several queries to guess the answer. For each query, you can think up three distinct indices $i, j, k$, and we will tell you the value of $\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$. In other words, we will tell you the difference between the maximum and the minimum number among $a_i$, $a_j$ and $a_k$.

You are allowed to make no more than $2 \cdot n - 2$ queries, and after that you have two tries to guess where the zero is. That is, you have to tell us two numbers $i$ and $j$ and you win if $a_i = 0$ or $a_j = 0$.

Can you guess where we hid the zero?

Note that the array in each test case is fixed beforehand and will not change during the game. In other words, the interactor is not adaptive.

Input

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

The first and only line of each test case contains an integer $n$ ($4 \le n \le 1000$) — the length of the array that we picked.

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

Interaction

For each test case, the interaction starts with reading $n$.

To make a query, print "? $i$ $j$ $k$" (without quotes, $1 \le i, j, k \le n$, indices must be distinct). Then you should read our response from standard input, that is, $\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k)$.

If the response is $-1$, it means your program has made an invalid query or has run out of tries. Your program must terminate immediately after reading $-1$, and you will get a verdict Wrong answer. Otherwise you may get any verdict, because the program will continue reading from the closed stream. Note that if the query is correct, the answer will never be $-1$ because $\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k) \geq 0$.

To give the final answer, print "! $i$ $j$" (without the quotes). Printing the same number twice (that is, $i = j$) is allowed. Note that giving this answer is not counted towards the limit of $2 \cdot n - 2$ queries. After that, your program must continue to solve the remaining test cases, or exit if all test cases have been solved.

After printing a query, don't forget to output line feed and flush the output buffer. Otherwise you will get the verdict Idleness limit exceeded. To flush the buffer, use:

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

Example

Input

```
1

4

2

3

3

2
```

Output

```
? 1 2 3

? 2 3 4

? 3 4 1

? 4 1 2

! 2 3
```

Note

Array from sample: $[1, 2, 0, 3]$.

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 const long long HARD_CAP = 200000; 


static ofstream log_fs;


static void log_metrics() {
    if (log_fs.is_open()) {
        log_fs << "queries=" << queries << endl;
        log_fs << "query_limit=" << query_limit << endl;
        log_fs.flush(); 
    }
}


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

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

    
    
    query_limit += (2LL * n - 2);
    
    log_metrics();

    
    cout << n << endl;

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

        
        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF reading token");
        }

        if (token == "!") {
            
            int i, j;
            if (!(cin >> i >> j)) {
                finish(_wa, "Unexpected EOF reading answer indices");
            }

            
            if (i < 1 || i > n || j < 1 || j > n) {
                finish(_wa, "Answer indices out of range");
            }

            
            if (a[i - 1] == 0 || a[j - 1] == 0) {
                case_solved = true;
            } else {
                finish(_wa, "Incorrect answer (neither index points to 0)");
            }
        } else {
            
            int i, j, k;

            
            if (token == "?") {
                if (!(cin >> i >> j >> k)) {
                    finish(_wa, "Unexpected EOF reading query indices");
                }
            } else {
                try {
                    i = stoi(token);
                } catch (...) {
                    finish(_wa, "Invalid token (expected '?' or integer): " + token);
                }
                if (!(cin >> j >> k)) {
                    finish(_wa, "Unexpected EOF reading query indices");
                }
            }

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

            
            bool valid = true;
            if (i < 1 || i > n || j < 1 || j > n || k < 1 || k > n) valid = false;
            if (i == j || i == k || j == k) valid = false;

            if (!valid) {
                cout << -1 << endl; 
                finish(_wa, "Invalid query (indices out of range or not distinct)");
            }

            
            int v1 = a[i - 1];
            int v2 = a[j - 1];
            int v3 = a[k - 1];
            int mx = max({v1, v2, v3});
            int mn = min({v1, v2, v3});
            cout << (mx - mn) << endl;
        }
    }
}

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

    
    if (argc > 2) {
        log_fs.open(argv[2], ios::out | ios::app);
    }
    
    
    atexit(log_metrics);

    
    int t = inf.readInt();
    cout << t << endl;

    while (t--) {
        solve_test_case();
    }

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


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 t = opt<int>("t", 1);
    
    int fixed_n = opt<int>("n", 0);

    
    if (mode != "non" && mode != "adp") {
        quitf(_fail, "Invalid mode '%s'. Expected 'non' or 'adp'.", mode.c_str());
    }

    cout << t << endl;

    long long current_n_sum = 0;
    const int MAX_SUM_N = 3000;

    for (int i = 0; i < t; ++i) {
        int n;
        if (fixed_n > 0) {
            n = fixed_n;
        } else {
            
            int remaining_cases = t - i;
            long long remaining_budget = MAX_SUM_N - current_n_sum;
            
            
            long long min_needed_future = 4LL * (remaining_cases - 1);
            long long max_current = remaining_budget - min_needed_future;
            
            
            int lower = 4;
            int upper = min((long long)1000, max_current);

            if (upper < lower) {
                quitf(_fail, "Cannot generate valid n: budget exhausted or constraints impossible.");
            }

            
            
            if (t <= 20) {
                
                n = rnd.wnext(lower, upper, 10);
            } else {
                
                n = rnd.next(lower, upper);
            }
        }
        
        current_n_sum += n;

        if (mode == "adp") {
            
            cout << n << endl;
        } else {
            
            cout << n << endl;

            vector<int> a(n);
            int zero_pos = rnd.next(0, n - 1);

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

            if (strategy <= 30) {
                
                for (int k = 0; k < n; k++) {
                    if (k == zero_pos) a[k] = 0;
                    else a[k] = rnd.next(1, 1000000000);
                }
            } else if (strategy <= 60) {
                
                set<int> s;
                while ((int)s.size() < n - 1) {
                    s.insert(rnd.next(1, 1000000000));
                }
                vector<int> vals(s.begin(), s.end());
                shuffle(vals.begin(), vals.end());
                int idx = 0;
                for (int k = 0; k < n; k++) {
                    if (k == zero_pos) a[k] = 0;
                    else a[k] = vals[idx++];
                }
            } else if (strategy <= 80) {
                
                int val1 = rnd.next(1, 1000000000);
                int val2 = rnd.next(1, 1000000000);
                for (int k = 0; k < n; k++) {
                    if (k == zero_pos) a[k] = 0;
                    else a[k] = (rnd.next(0, 1) ? val1 : val2);
                }
            } else {
                
                int base = rnd.next(1, 999900000);
                for (int k = 0; k < n; k++) {
                    if (k == zero_pos) a[k] = 0;
                    else a[k] = base + rnd.next(0, 1000);
                }
            }

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

    return 0;
}