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

This is the simple version of the problem. The only difference between the versions is the limit on the number of queries. In this version, you can make no more than 100 queries.

This is an interactive problem!

salyg1n has given you a positive integer $k$ and wants to play a game with you. He has chosen an array of $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$). You must print $a_1 \oplus a_2 \oplus \ldots \oplus a_n$, where $\oplus$ denotes the bitwise XOR operation. You can make queries of the following type:

* $?$ $i$: in response to this query, you will receive $a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1}$. Also, after this query, the subarray $a_i, a_{i + 1}, \ldots, a_{i + k - 1}$ will be reversed, i.e., the chosen array $a$ will become: $a_1, a_2, \ldots a_{i - 1}, a_{i + k - 1}, a_{i + k - 2}, \ldots, a_{i + 1}, a_i, a_{i + k}, \ldots, a_n$.

You can make no more than $100$ queries to answer the problem.

Input

The first line contains a single integer $t$ ($1 \leq t \leq 1000$) – the number of test cases.

Interaction

The interaction between your program and the jury's program begins with reading two positive even integers $n$ and $k$ ($1 \leq k \leq n \leq k^2 \leq 2500$) – the length of the chosen array and the length of the query subarray, respectively.

To find the value of $a_i \oplus a_{i + 1} \oplus \ldots \oplus a_{i + k - 1}$, print the query in the format $?$ $i$ ($1 \leq i \leq n - k + 1$). Then read a single integer – the answer to your query.

You can make no more than $100$ queries. When you are ready to print the answer, output it in the format $!$ $x$. After that, proceed to process the next test case or terminate the program if it was the last test case. Printing the answer does not count as one of the $100$ queries.

If your program makes more than $100$ queries for one set of input data, or makes an invalid query, then the response to the query will be -1. After receiving such a response, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.

After printing a query 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.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10000$. The interactor in this problem is not adaptive.

Example

Input

```
2
4 2

6

4

6 6

4
```

Output

```? 1? 3! 2? 1! 4
```

Note

In the first test case, the jury has chosen the array $a$ $=$ $[4, 2, 5, 1]$

In the second test case, the jury has chosen the array $a$ $=$ $[5, 7, 1, 3, 3, 7]$

Non-adaptive interactor (C++):























#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;


static int current_queries = 0;
static int max_queries_seen = 0;
static const int QUERY_LIMIT = 100;

void finish(TResult verdict, const string& msg);

static int smallest_even_sqrt_at_least(int n) {
    int r = (int)ceil(sqrt((long double)n));
    if (r % 2 != 0) r++;
    return r;
}

static int sanitize_k(int n, int k_in) {
    auto is_valid = [&](int k) -> bool {
        return k >= 1 && k <= n && k % 2 == 0 && 1LL * k * k >= n && 1LL * k * k <= 2500;
    };

    if (is_valid(k_in)) return k_in;

    int k = min(n, 50);
    if (k % 2 != 0) k--;
    if (k < 2) k = 2;
    if (k > n) k = n - (n % 2);

    if (is_valid(k)) return k;

    
    int min_k = smallest_even_sqrt_at_least(n);
    if (min_k > 50) {
        
        finish(_fail, format("Invalid test constraints: n=%d cannot satisfy n<=k^2<=2500", n));
    }
    if (min_k > n) {
        finish(_fail, format("Invalid test constraints: n=%d cannot satisfy k<=n with even k", n));
    }
    return min_k;
}


void log_metrics() {
    
    
    
    int q = max(max_queries_seen, current_queries);
    try {
        tout << "queries=" << q << endl;
        tout << "query_limit=" << QUERY_LIMIT << endl;
    } catch (...) {
        
    }
}


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;

    for (int cas = 1; cas <= t; ++cas) {
        
        current_queries = 0;

        
        int n = inf.readInt();
        int k_in = inf.readInt();
        
        
        vector<int> a(n);
        long long initial_xor_sum = 0;
        for (int i = 0; i < n; ++i) {
            a[i] = inf.readInt();
            initial_xor_sum ^= a[i];
        }

        int k = sanitize_k(n, k_in);

        
        cout << n << " " << k << endl;

        
        bool case_active = true;
        while (case_active) {
            string token;
            if (!(cin >> token)) {
                finish(_pe, format("Unexpected end of file while reading query/answer in case %d", cas));
            }

            if (token == "!") {
                
                long long ans;
                if (!(cin >> ans)) {
                    finish(_pe, "Expected integer answer after '!'");
                }

                
                
                
                if (ans != initial_xor_sum) {
                    finish(_wa, format("Wrong answer in case %d: expected %lld, found %lld", cas, initial_xor_sum, ans));
                }

                
                if (current_queries > max_queries_seen) {
                    max_queries_seen = current_queries;
                }
                case_active = false;
            } else if (token == "?") {
                
                int i;
                if (!(cin >> i)) {
                    finish(_pe, "Expected integer index after '?'");
                }

                current_queries++;
                
                
                if (current_queries > QUERY_LIMIT) {
                    cout << -1 << endl;
                    finish(_wa, format("Query limit exceeded (>%d) in test case %d", QUERY_LIMIT, cas));
                }

                
                if (i < 1 || i > n - k + 1) {
                    cout << -1 << endl;
                    finish(_wa, format("Invalid query index %d in case %d (n=%d, k=%d)", i, cas, n, k));
                }

                
                long long subarray_xor = 0;
                for (int j = 0; j < k; ++j) {
                    subarray_xor ^= a[i - 1 + j];
                }

                
                reverse(a.begin() + (i - 1), a.begin() + (i - 1) + k);

                
                cout << subarray_xor << endl;
            } else {
                finish(_pe, format("Invalid protocol token '%s' in case %d (expected '?' or '!')", token.c_str(), cas));
            }
        }
    }

    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");

    vector<pair<int, int>> cases;
    long long sum_n = 0;
    const int MAX_SUM_N = 10000;
    
    
    auto try_add = [&](int n, int k) -> bool {
        if (n % 2 != 0) return false;
        if (k % 2 != 0) return false;
        if (k > n) return false;
        if (1LL * k * k < n) return false;
        if (1LL * k * k > 2500) return false;
        if (n > 2500) return false;
        if (sum_n + n > MAX_SUM_N) return false;
        
        cases.push_back({n, k});
        sum_n += n;
        return true;
    };

    
    if (string(argv[1]) == "1") {
        try_add(2, 2);
        try_add(4, 2);
        try_add(6, 2);
        try_add(4, 4);
        try_add(6, 4); 
        try_add(10, 4); 
        try_add(16, 4); 
        
        
        try_add(100, 10);  
        try_add(100, 12);
        try_add(50, 50); 

        
        try_add(2500, 50); 
        try_add(2400, 50);
        
        
        try_add(2350, 50);
    }

    
    while (sum_n < MAX_SUM_N) {
        int remaining = (int)(MAX_SUM_N - sum_n);
        if (remaining < 2) break;
        
        
        int limit_n = min(2500, remaining);
        if (limit_n < 2) break;

        
        int n;
        int n_type = rnd.next(1, 10);
        
        if (n_type <= 2) {
            
            n = rnd.next(2, min(limit_n, 50));
        } else if (n_type <= 8) {
            
            n = rnd.next(2, limit_n);
        } else {
            
            int lower = max(2, limit_n - 200);
            n = rnd.next(lower, limit_n);
        }
        
        if (n % 2 != 0) n--;
        if (n < 2) n = 2; 

        
        
        int min_k = ceil(sqrt(n));
        if (min_k % 2 != 0) min_k++;
        
        if (min_k > n) {
            
            continue;
        }

        int max_k = min(n, 50);
        if (max_k % 2 != 0) max_k--;
        int k_range_steps = (max_k - min_k) / 2;
        int k;
        
        if (k_range_steps == 0) {
            k = min_k;
        } else {
            int k_type = rnd.next(1, 5);
            if (k_type == 1) k = min_k; 
            else if (k_type == 2) k = max_k; 
            else if (k_type == 3) { 
                int step = rnd.next(1, min(5, k_range_steps));
                k = min_k + 2 * step;
            } else if (k_type == 4) { 
                int step = rnd.next(1, min(5, k_range_steps));
                k = max_k - 2 * step;
            } else { 
                int step = rnd.next(0, k_range_steps);
                k = min_k + 2 * step;
            }
        }
        
        if (!try_add(n, k)) {
            
            if (limit_n <= 4) break;
        }
    }

    
    println(cases.size());
    for (const auto& p : cases) {
        int n = p.first;
        int k = p.second;
        println(n, k);
        
        if (mode == "non") {
            
            vector<int> a(n);
            for (int i = 0; i < n; i++) {
                a[i] = rnd.next(1, 1000000000);
            }
            println(a);
        }
        
        
    }

    return 0;
}