Problem: cf2036_g
Difficulty: medium
Categories: bit, search
Time limit: 2000 ms, memory limit: 256 MB

This is an interactive problem.

The Department of Supernatural Phenomena at the Oxenfurt Academy has opened the Library of Magic, which contains the works of the greatest sorcerers of Redania — $n$ ($3 \leq n \leq 10^{18}$) types of books, numbered from $1$ to $n$. Each book's type number is indicated on its spine. Moreover, each type of book is stored in the library in exactly two copies! And you have been appointed as the librarian.

One night, you wake up to a strange noise and see a creature leaving the building through a window. Three thick tomes of different colors were sticking out of the mysterious thief's backpack. Before you start searching for them, you decide to compute the numbers $a$, $b$, and $c$ written on the spines of these books. All three numbers are distinct.

So, you have an unordered set of tomes, which includes one tome with each of the pairwise distinct numbers $a$, $b$, and $c$, and two tomes for all numbers from $1$ to $n$, except for $a$, $b$, and $c$. You want to find these values $a$, $b$, and $c$.

Since you are not working in a simple library, but in the Library of Magic, you can only use one spell in the form of a query to check the presence of books in their place:

* "xor l r" — Bitwise XOR query with parameters $l$ and $r$. Let $k$ be the number of such tomes in the library whose numbers are greater than or equal to $l$ and less than or equal to $r$. You will receive the result of the computation $v_1 \oplus v_2 \oplus... \oplus v_k$, where $v_1... v_k$ are the numbers on the spines of these tomes, and $\oplus$ denotes the operation of bitwise exclusive OR.

Since your magical abilities as a librarian are severely limited, you can make no more than $150$ queries.

Input

The first line of input contains an integer $t$ ($1 \le t \le 300$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($3 \leq n \leq 10^{18}$) — the number of types of tomes.

Interaction

The interaction for each test case begins with reading the integer $n$.

Then you can make up to $150$ queries.

To make a query, output a string in the format "xor l r" (without quotes) ($1 \leq l \leq r \leq n$). After each query, read an integer — the answer to your query.

To report the answer, output a string in the format "ans a b c" (without quotes), where $a$, $b$, and $c$ are the numbers you found as the answer to the problem. You can output them in any order.

The interactor is not adaptive, which means that the answer is known before the participant makes queries and does not depend on the queries made by the participant.

After making $150$ queries, the answer to any other query will be $-1$. Upon receiving such an answer, terminate the program to receive a verdict of "WA" (Wrong answer).

After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive a verdict of "IL" (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;
* refer to the documentation for other languages.

Example

Input

```
2
6

0

2

3

5

3
```

Output

```
xor 1 1

xor 2 2

xor 3 3

xor 4 6

ans 2 3 5

ans 1 2 3
```

Note

In the first test case, the books in the library after the theft look like this:![](https://espresso.codeforces.com/68391415c7555737d5c6224fa63d1891c2bd552e.png)

Now consider the answers to the queries:

* For the query "xor 1 1", you receive the result $1 \oplus 1 = 0$. Two tomes satisfy the condition specified in the query — both with the number $1$.
* For the query "xor 2 2", you receive the result $2$, as only one tome satisfies the specified condition.
* For the query "xor 3 3", you receive the result $3$.
* For the query "xor 4 6", you receive the result $4 \oplus 6 \oplus 4 \oplus 5 \oplus 6 = 5$.

In the second test case, there are only $3$ types of books, and it is easy to guess that the missing ones have the numbers $1$, $2$, and $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 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 readLongLongFromCin(long long &out) {
    
    cin >> out;
    return (bool)cin;
}

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

    long long t = 0;
    try {
        t = inf.readLong();
    } catch (...) {
        
        query_limit = 0;
        log_metrics();
        return 0;
    }
    if (t < 1 || t > 300) {
        query_limit = 0;
        log_metrics();
        quitf(_fail, "Invalid t in hidden input: %lld", t);
    }

    struct CaseData {
        long long n, a, b, c;
    };
    vector<CaseData> cases;
    cases.reserve((size_t)t);

    for (long long i = 0; i < t; i++) {
        long long n = inf.readLong();
        long long a = inf.readLong();
        long long b = inf.readLong();
        long long c = inf.readLong();
        cases.push_back({n, a, b, c});
    }

    query_limit = 150LL * t;
    log_metrics(); 

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

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

    for (long long tc = 0; tc < t; tc++) {
        const long long n = cases[tc].n;
        const long long A = cases[tc].a;
        const long long B = cases[tc].b;
        const long long C = cases[tc].c;

        if (!(3LL <= n && n <= 1000000000000000000LL)) finish(_fail, "Invalid n in hidden input");
        auto inRange = [&](long long x) { return 1LL <= x && x <= n; };
        if (!inRange(A) || !inRange(B) || !inRange(C) || A == B || A == C || B == C)
            finish(_fail, "Invalid (a,b,c) in hidden input");

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

        long long case_queries = 0;
        while (true) {
            if (queries > hard_cap) finish(_pe, "Hard cap exceeded");

            string cmd;
            if (!(cin >> cmd)) finish(_pe, "Unexpected EOF from contestant");

            if (cmd == "xor") {
                long long l, r;
                if (!readLongLongFromCin(l) || !readLongLongFromCin(r))
                    finish(_pe, "Malformed xor query (expected two integers)");

                if (!(1LL <= l && l <= r && r <= n))
                    finish(_pe, "Invalid xor query bounds");

                queries++;
                case_queries++;

                if (case_queries > 150) {
                    cout << -1 << "\n";
                    cout.flush();
                    continue;
                }

                long long res = 0;
                if (l <= A && A <= r) res ^= A;
                if (l <= B && B <= r) res ^= B;
                if (l <= C && C <= r) res ^= C;

                cout << res << "\n";
                cout.flush();
            } else if (cmd == "ans") {
                long long x, y, z;
                if (!readLongLongFromCin(x) || !readLongLongFromCin(y) || !readLongLongFromCin(z))
                    finish(_pe, "Malformed ans (expected three integers)");

                if (!inRange(x) || !inRange(y) || !inRange(z) || x == y || x == z || y == z)
                    finish(_wa, "Invalid answer values");

                array<long long, 3> got = {x, y, z};
                array<long long, 3> want = {A, B, C};
                sort(got.begin(), got.end());
                sort(want.begin(), want.end());

                if (got != want) finish(_wa, "Wrong answer");

                if (tc + 1 == t) finish(_ok, "OK");
                break; 
            } else {
                finish(_pe, "Unknown command (expected 'xor' or 'ans')");
            }
        }
    }

    finish(_pe, "Contestant did not finish all testcases");
    return 0;
}


Adaptive interactor (C++):

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

static long long highestPow2LE(long long n) {
    long long p = 1;
    while ((p << 1) > 0 && (p << 1) <= n) p <<= 1;
    return p;
}

static long long pickNotIn(long long n, const vector<long long>& used) {
    while (true) {
        long long x = rnd.next(1LL, n);
        bool ok = true;
        for (long long u : used) if (x == u) { ok = false; break; }
        if (ok) return x;
    }
}

static void ensureDistinctInRange(long long n, long long &a, long long &b, long long &c) {
    auto inRange = [&](long long x) { return 1LL <= x && x <= n; };
    if (!inRange(a)) a = rnd.next(1LL, n);
    if (!inRange(b)) b = rnd.next(1LL, n);
    if (!inRange(c)) c = rnd.next(1LL, n);

    if (a == b) b = pickNotIn(n, {a});
    if (a == c) c = pickNotIn(n, {a, b});
    if (b == c) c = pickNotIn(n, {a, b});
}

static void genTriple(long long n, long long seed, long long &a, long long &b, long long &c) {
    
    if (seed == 1) {
        a = 1; b = 2; c = 3; 
        return;
    }
    if (seed == 2) {
        a = 1;
        b = n - 1;
        c = n; 
        return;
    }
    if (seed == 3) {
        long long x = (1LL << 58);
        a = 1;
        b = x;
        c = x + 1; 
        if (c > n) {
            
            a = n;
            b = n - 1;
            c = 1;
        }
        return;
    }

    
    int type = rnd.next(0, 99);

    if (type < 50) {
        
        long long k = highestPow2LE(n);
        a = k;
        b = k - 1;
        c = 1;
        if (k <= 2) {
            
            a = 1; b = 2; c = 3;
        } else if (b == c) {
            c = 2;
        }
        ensureDistinctInRange(n, a, b, c);
        return;
    }

    if (type < 75) {
        
        bool ok = false;
        for (int it = 0; it < 200; it++) {
            long long x = rnd.next(1LL, n);
            long long y = rnd.next(1LL, n);
            if (x == y) continue;
            long long z = x ^ y;
            if (1LL <= z && z <= n && z != x && z != y) {
                a = x; b = y; c = z;
                ok = true;
                break;
            }
        }
        if (ok) return;
        
    }

    
    long long third1 = max(1LL, n / 3);
    long long third2 = max(third1 + 1, (2 * n) / 3);

    a = rnd.next(1LL, third1);
    b = rnd.next(min(third1 + 1, n), min(third2, n));
    c = rnd.next(min(third2 + 1, n), n);

    ensureDistinctInRange(n, a, b, c);
}

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

    string mode = opt<string>("mode", "non");
    long long fixedN = opt<long long>("n", 0LL);
    long long nmin = opt<long long>("nmin", 3LL);
    long long nmax = opt<long long>("nmax", 1000000000000000000LL);

    ensuref(nmin >= 3, "nmin must be >= 3");
    ensuref(nmax >= nmin, "nmax must be >= nmin");

    long long seed = 1;
    if (argc > 1) seed = atoll(argv[1]);

    long long n;
    if (fixedN != 0) {
        n = fixedN;
    } else if (seed == 1) {
        n = 3;
    } else if (seed == 2) {
        n = 1000000000000000000LL;
    } else if (seed == 3) {
        n = 999999999999999937LL;
    } else {
        long long span = nmax - nmin;
        long long delta = 0;
        if (span > 0) delta = rnd.next(0LL, min(1000000LL, span));
        n = nmax - delta;
        if (n < nmin) n = nmin;
        if (n > nmax) n = nmax;
    }

    ensuref(3LL <= n && n <= 1000000000000000000LL, "n out of bounds");

    if (mode == "non") {
        long long a = 1, b = 2, c = 3;
        genTriple(n, seed, a, b, c);
        ensureDistinctInRange(n, a, b, c);
        ensuref(a != b && a != c && b != c, "a,b,c must be distinct");
        cout << 1 << "\n";
        cout << n << "\n";
        cout << a << " " << b << " " << c << "\n";
        return 0;
    }

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

    quitf(_fail, "Unknown --mode (expected non/adp): %s", mode.c_str());
}