Oh no, this wicked jury hides something from you again, and you need to guess it interactively.

This time, you need to find an integer $n$ . To do that, you can make at most 10 queries of the form “What is the $k$ -th decimal digit of the product of all integers from 1 to $n$ (also known as factorial and denoted as $n .$ !)?”.

# Interaction Protocol

In the first line, there is an integer $t$ ( $1 \leq t \leq 1 0 0$ ) — the number of tests you shall process.

For each test, the integer $n$ is chosen in advance. The length of $n !$ is at most $2 0 0 0 0$ , so $1 \leq n \leq 5 9 8 2$ .

You can make at most 10 queries of the form $" ? ~ k "$ ( $0 \leq k < 2 0 0 0 0$ ). In response to the query, you will get a single digit — the $k$ -th decimal digit of $n$ ! (the response is between 0 and 9 inclusive). Digits are numbered from 0, starting with the least significant digit. If $n$ ! is too short, and there is no $k$ -th digit, then 0 is returned.

After your program finds the value of $n$ it shall answer with “! $n$ ”. If the answer is correct, then you will receive “YES” and should proceed to the next test or terminate if it was the last one. If the answer is not correct, or you are trying to guess, and there are several possible answers consistent with the information you have received, you will get “NO”. In that case, your submission will receive “Wrong answer” verdict and your code shall terminate immediately.

# Example

standard input	standard output

2	？0

1

YES	！1

0	？0

2	？ 19997

	！5982

YES

#include "testlib.h"
#include <array>
#include <bits/stdc++.h>

using namespace std;

static constexpr int MAX_N = 5982;
static constexpr int MAX_K = 20000;
static constexpr int QUERY_LIMIT_PER_TEST = 10;

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 (...) {}
}

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

static vector<array<uint8_t, MAX_K>> factorial_digits;

static void precompute_factorial_digits() {
    factorial_digits.assign(MAX_N + 1, {});

    static constexpr int BASE = 10000;
    vector<int> cur = {1};

    for (int n = 1; n <= MAX_N; ++n) {
        long long carry = 0;
        for (size_t i = 0; i < cur.size(); ++i) {
            long long val = 1LL * cur[i] * n + carry;
            cur[i] = static_cast<int>(val % BASE);
            carry = val / BASE;
        }
        while (carry > 0) {
            cur.push_back(static_cast<int>(carry % BASE));
            carry /= BASE;
        }

        auto& out = factorial_digits[n];

        for (size_t i = 0; i + 1 < cur.size(); ++i) {
            int v = cur[i];
            for (int d = 0; d < 4; ++d) {
                int pos = static_cast<int>(i) * 4 + d;
                if (pos >= MAX_K) break;
                out[pos] = static_cast<uint8_t>(v % 10);
                v /= 10;
            }
        }

        int v = cur.back();
        for (int d = 0; d < 4; ++d) {
            int pos = static_cast<int>(cur.size() - 1) * 4 + d;
            if (pos >= MAX_K) break;
            out[pos] = static_cast<uint8_t>(v % 10);
            v /= 10;
            if (v == 0) break;
        }
    }
}

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

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    precompute_factorial_digits();

    int t = inf.readInt(1, 100, "t");
    vector<int> ns(t);
    for (int i = 0; i < t; ++i) ns[i] = inf.readInt(1, MAX_N, format("n[%d]", i + 1).c_str());

    query_limit = 1LL * QUERY_LIMIT_PER_TEST * t;
    log_metrics();

    cout << t << endl;

    for (int tc = 0; tc < t; ++tc) {
        const int hidden_n = ns[tc];

        int queries_this_test = 0;
        vector<char> possible(MAX_N + 1, 1);
        possible[0] = 0;
        int possible_count = MAX_N;

        while (true) {
            string tok;
            if (!(cin >> tok)) finish(_pe, "Unexpected EOF while reading operation");

            if (!tok.empty() && tok[0] == '?') {
                int k = INT_MIN;
                if (tok.size() == 1) {
                    if (!(cin >> k)) finish(_pe, "Expected k after '?'");
                } else {
                    try {
                        k = stoi(tok.substr(1));
                    } catch (...) {
                        finish(_pe, "Invalid query token");
                    }
                }

                if (queries_this_test >= QUERY_LIMIT_PER_TEST) {
                    cout << "NO" << endl;
                    finish(_wa, "Query limit exceeded");
                }
                if (k < 0 || k >= MAX_K) {
                    cout << "NO" << endl;
                    finish(_wa, "k out of range");
                }

                const int d = static_cast<int>(factorial_digits[hidden_n][k]);
                cout << d << endl;

                for (int cand = 1; cand <= MAX_N; ++cand) {
                    if (!possible[cand]) continue;
                    if (static_cast<int>(factorial_digits[cand][k]) != d) {
                        possible[cand] = 0;
                        --possible_count;
                    }
                }

                ++queries_this_test;
                ++queries;
                log_metrics();
                continue;
            }

            if (!tok.empty() && tok[0] == '!') {
                int guess = INT_MIN;
                if (tok.size() == 1) {
                    if (!(cin >> guess)) finish(_pe, "Expected n after '!'");
                } else {
                    try {
                        guess = stoi(tok.substr(1));
                    } catch (...) {
                        finish(_pe, "Invalid answer token");
                    }
                }

                if (guess != hidden_n) {
                    cout << "NO" << endl;
                    finish(_wa, "Wrong answer");
                }
                if (possible_count != 1 || !possible[hidden_n]) {
                    cout << "NO" << endl;
                    finish(_wa, "Ambiguous answer");
                }

                cout << "YES" << endl;
                break;
            }

            finish(_pe, "Expected '?' or '!'");
        }
    }

    finish(_ok, "All tests solved");
}

#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 MAX_N = 5982;

    if (mode == "adp") {

        int t = 100;
        println(t);
        for (int i = 0; i < t; i++) {
            println(1, MAX_N);
        }
        return 0;
    }

    int seed_val = atoi(argv[1]);
    vector<int> ns;

    if (seed_val == 1) {

        ns = {1, 2, 3, 4, 5, 9, 10, 19, 20, 50,
              100, 500, 1000, 2000, 3000, 4000, 5000,
              MAX_N - 2, MAX_N - 1, MAX_N};
    } else if (seed_val == 2) {

        for (int k = 1; k <= MAX_N; k *= 2) ns.push_back(k);
        for (int k = 1; k <= MAX_N; k *= 10) ns.push_back(k);

        vector<int> extra;
        for (int x : ns) {
            if (x > 1) extra.push_back(x - 1);
            if (x < MAX_N) extra.push_back(x + 1);
        }
        ns.insert(ns.end(), extra.begin(), extra.end());

        sort(ns.begin(), ns.end());
        ns.erase(unique(ns.begin(), ns.end()), ns.end());
    } else if (seed_val == 3) {

        for (int k = 1; k <= MAX_N; k += 59) {
            ns.push_back(k);
        }
        if (ns.back() != MAX_N) ns.push_back(MAX_N);
    } else {

        int t = 100;
        for (int i = 0; i < t; i++) {
            ns.push_back(rnd.next(1, MAX_N));
        }
    }

    if (ns.size() > 100) {
        shuffle(ns.begin(), ns.end());
        ns.resize(100);
    } else {

        shuffle(ns.begin(), ns.end());
    }

    if (ns.empty()) ns.push_back(MAX_N);

    println(ns.size());
    for (int x : ns) {
        println(x);
    }

    return 0;
}


Dimash learned that Mansur wrote something very unpleasant about him to a friend, so he decided to find out his password at all costs and discover what exactly he wrote.

Believing in the strength of his password, Mansur stated that his password — is a binary string of length $n$. He is also ready to answer Dimash's questions of the following type:

Dimash says a binary string $t$, and Mansur replies whether it is true that $t$ is a substring of his password.

Help Dimash find out the password in no more than $2n$ operations; otherwise, Mansur will understand the trick and stop communicating with him.

Input

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

Interaction

At the beginning of each test case, first read $n$ ($1 \le n \le 100$) — the size of the binary string. Then proceed to guessing it.

To guess each string $s$, you can make no more than $2n$ queries of the following type:

* "? t", where $t$ is a binary string such that ($1 \le |t| \le n$).

In response to this query, you will receive $1$ if $t$ is a substring of $s$, and $0$ otherwise.

Once you receive the answer, output a single string in the following format:

* "! s", where $s$ is a binary string of size $n$.

After that, proceed to solve the next test case.

If you make an incorrect attempt or exceed the limit of $2n$ attempts, you will receive $-1$ instead of an answer and get the verdict Wrong answer. In this case, your program should terminate immediately to avoid undefined verdicts.

After outputting the queries, do not forget to output a newline character and flush the output buffer. Otherwise, you will receive the verdict Solution "hung". 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

```
4
3

0

0

1

4

4

2
```

Output

```
? 00

? 000

? 010

! 010

! 1100

! 0110

! 10
```

Note

In the first example, the string $010$ is given. Therefore, the answers to the queries are as follows:

"? 00" $00$ is not a substring of $010$, so the answer is $0$.

"? 000" $000$ is not a substring, so the answer is $0$.

"? 010" $010$ is a substring, so the answer is $1$.

In the second example, the string is $1100$, in the third $0110$, and in the fourth $10$.

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

    vector<string> cases;
    cases.reserve(t);
    for (int i = 0; i < t; i++) {
        string s = inf.readToken();
        cases.push_back(s);

        query_limit += 2LL * s.length();
    }

    log_metrics();

    cout << t << endl;

    for (const string& s : cases) {
        int n = (int)s.length();

        cout << n << endl;

        bool solved = false;
        while (!solved) {

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

            if (queries > HARD_CAP) {
                finish(_pe, "Hard query limit exceeded");
            }

            string type;
            if (!(cin >> type)) {
                finish(_wa, "Unexpected EOF (expected '?' or '!')");
            }

            if (type == "!") {

                string guess;
                if (!(cin >> guess)) {
                    finish(_wa, "Unexpected EOF after '!'");
                }

                if (guess == s) {
                    solved = true;
                } else {
                    finish(_wa, format("Incorrect password. Expected '%s', found '%s'", s.c_str(), guess.c_str()));
                }
            } else if (type == "?") {

                string t_guess;
                if (!(cin >> t_guess)) {
                    finish(_wa, "Unexpected EOF after '?'");
                }

                queries++;

                bool found = false;

                if (t_guess.length() <= s.length()) {
                    if (s.find(t_guess) != string::npos) {
                        found = true;
                    }
                }

                cout << (found ? 1 : 0) << endl;
            } else {

                finish(_pe, format("Invalid token '%s'. Expected '?' or '!'", type.c_str()));
            }
        }
    }

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

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long total_queries = 0;
static long long total_limit = 0;
static bool metrics_logged = false;

void log_metrics() {
    if (metrics_logged) return;
    metrics_logged = true;

    if (total_limit == 0) total_limit = 1;

    tout << "queries=" << total_queries << endl;
    tout << "query_limit=" << total_limit << endl;
}

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

string get_complement(string s) {
    for(char &c : s) c = (c == '0' ? '1' : '0');
    return s;
}

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

    registerInteraction(argc, argv);
    atexit(log_metrics);

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

    for(int i = 0; i < t; ++i) {

        string token = inf.readToken();
        int n;
        string s_base;

        bool is_binary = true;
        if (token.empty()) is_binary = false;
        for(char c : token) if(c != '0' && c != '1') is_binary = false;

        if(!is_binary) {
            n = stoi(token);

            s_base = "";
            for(int k=0; k<n; ++k) s_base += (rnd.next(2) ? '1' : '0');
        } else {
            s_base = token;
            n = s_base.length();
        }

        set<string> candidates;
        candidates.insert(s_base);
        candidates.insert(get_complement(s_base));
        string s_rev = s_base;
        reverse(s_rev.begin(), s_rev.end());
        candidates.insert(s_rev);
        candidates.insert(get_complement(s_rev));

        cout << n << endl;

        long long case_limit = 2 * n;
        total_limit += case_limit;

        long long case_queries = 0;
        bool solved = false;

        while(true) {

            if (total_queries > 500000) finish(_pe, "Total hard query limit exceeded");

            string type;
            if (!(cin >> type)) finish(_wa, "Unexpected EOF from solution");

            if (type == "?") {
                case_queries++;
                total_queries++;

                if (case_queries > case_limit) {
                    finish(_wa, "Too many queries for this test case");
                }

                string q_str;
                cin >> q_str;

                if (q_str.length() < 1 || q_str.length() > (size_t)n) {
                    finish(_pe, "Invalid query string length");
                }

                int yes_cnt = 0;
                int no_cnt = 0;
                for(const string& cand : candidates) {
                    if(cand.find(q_str) != string::npos) yes_cnt++;
                    else no_cnt++;
                }

                bool ans = (yes_cnt >= no_cnt);
                cout << (ans ? 1 : 0) << endl;

                auto it = candidates.begin();
                while(it != candidates.end()) {
                    bool has = (it->find(q_str) != string::npos);
                    if (has != ans) {
                        it = candidates.erase(it);
                    } else {
                        ++it;
                    }
                }

                if(candidates.empty()) finish(_fail, "Interactor internal error: valid set empty");

            } else if (type == "!") {
                string ans_str;
                cin >> ans_str;

                if (candidates.count(ans_str)) {
                    solved = true;
                } else {
                    finish(_wa, "Wrong answer");
                }
                break;
            } else {
                finish(_pe, "Invalid query type");
            }
        }

        if (!solved) finish(_wa, "Loop exited without solution");
    }

    finish(_ok, "All cases passed");
    return 0;
}

#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", rnd.next(10, 50));

    t = max(1, min(100, t));

    int fixed_n = opt<int>("n", -1);

    cout << t << endl;

    for (int i = 0; i < t; ++i) {
        int n;
        if (fixed_n != -1) {
            n = fixed_n;
        } else {

            int p = rnd.next(100);
            if (p < 10) n = rnd.next(1, 5);
            else if (p < 30) n = rnd.next(6, 20);
            else if (p < 75) n = rnd.next(21, 70);
            else n = rnd.next(71, 100);
        }

        n = max(1, min(100, n));

        if (mode == "adp") {

            cout << n << endl;
        } else {

            string s = "";
            int type = rnd.next(10);

            if (type <= 2) {

                for (int j = 0; j < n; ++j) s += (char)('0' + rnd.next(2));
            } else if (type == 3) {

                s = string(n, '0');
            } else if (type == 4) {

                s = string(n, '1');
            } else if (type == 5) {

                int start = rnd.next(2);
                for (int j = 0; j < n; ++j) s += (char)('0' + (start ^ (j & 1)));
            } else if (type == 6) {

                if (n == 1) {
                    s += (char)('0' + rnd.next(2));
                } else {
                    int split = rnd.next(1, n - 1);
                    int first = rnd.next(2);
                    for (int j = 0; j < split; ++j) s += (char)('0' + first);
                    for (int j = split; j < n; ++j) s += (char)('0' + (1 - first));
                }
            } else if (type == 7) {

                int mainBit = rnd.next(2);
                for (int j = 0; j < n; ++j) {
                    if (rnd.next(10) == 0) s += (char)('0' + (1 - mainBit));
                    else s += (char)('0' + mainBit);
                }
            } else if (type == 8) {

                if (n < 4) {
                    for (int j = 0; j < n; ++j) s += (char)('0' + rnd.next(2));
                } else {
                    int len = rnd.next(2, n / 2);
                    string pat = "";
                    for (int j = 0; j < len; ++j) pat += (char)('0' + rnd.next(2));
                    for (int j = 0; j < n; ++j) s += pat[j % len];
                }
            } else {

                string half = "";
                for (int j = 0; j < (n + 1) / 2; ++j) half += (char)('0' + rnd.next(2));
                s = half;
                for (int j = n / 2 - 1; j >= 0; --j) s += half[j];
            }
            cout << s << endl;
        }
    }

    return 0;
}


The two versions have different constraints on $k$, $c$. Solving one of the two versions does not necessarily solve the other. You may want to read both versions.

This is an interactive problem.

During the time of the Ottoman Empire, many scientists were at work. You decided to study their daily life and stumbled upon an interesting game that was popular at that time. One scientist would think of an integer $x$, such that $1 \leq x \leq c$. Another scientist would try to guess it. He could specify the base of the numeral system $2 \leq b \leq c$ and would receive as a response the sum of the digits of the number $x$ in base $b$, if $x \geq b$, or $-1$ if $x < b$.

You wrote a program that can think of a number $x$ and respond to the question. Now you want to play with it and learn to guess using $\leq k$ queries.

Input

The first line contains three integers $t$, $k$, $c$ ($1 \leq t \leq 10^4$, $\mathbf{k=3}$, $\mathbf{c=2\cdot10^9}$). You must guess the number from $1$ to $c$ $t$ times, using $\leq k$ queries. All $t$ games will be played consecutively and are independent.

Interaction

To make a query, you must output ? $b$ for some $2 \leq b \leq c$. Then you must read the response — an integer $a$ ($-1 \leq a < c$) — the response to the query.

To provide the guessed number, you must output ! $x$, where $1 \leq x \leq c$ — your answer. Then you must read the result $r$ ($0 \leq r \leq 1$). If $r = 0$ — your answer is incorrect, you must immediately terminate the program in this case. Otherwise, if $r = 1$ — your answer is correct, you can proceed to the next game or terminate the program if $t$ games have already been played.

It is guaranteed that the interactor is not adaptive. That is, all chosen numbers are fixed in advance and do not change during the games.

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

If, at any interaction step, you read -2 instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

$^{\text{∗}}$To flush, use:

* fflush(stdout) or cout.flush() in C++;
* sys.stdout.flush() in Python;
* see the documentation for other languages.

Example

Input

```
3 3 2000000000

1

1

7

1

-1

1

-1

6

6

1
```

Output

```
? 10

? 1000

? 2

! 1000000

? 2

! 1

? 100

? 10

? 5

! 42
```

Note

In the first game, the hidden number is $1000000_{10} = 100_{1000} = 11110100001001000000_2$. The sums of digits are $1$, $1$, and $7$ in these bases.

In the second game, the hidden number is $1$. The query with $b = 2$ returns $-1$.

In the third game, the hidden number is $42_{10} = 132_{5}$.

#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 readToken(string& s) {
    s.clear();
    if (!(cin >> s)) return false;
    return true;
}

static bool parseLongLongStrict(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '+' || s[0] == '-') i = 1;
    if (i == (int)s.size()) return false;
    for (; i < (int)s.size(); i++) {
        if (s[i] < '0' || s[i] > '9') return false;
    }
    try {
        size_t pos = 0;
        long long v = stoll(s, &pos, 10);
        if (pos != s.size()) return false;
        out = v;
        return true;
    } catch (...) {
        return false;
    }
}

static long long digitSumBase(long long x, long long b) {
    long long sum = 0;
    while (x > 0) {
        sum += x % b;
        x /= b;
    }
    return sum;
}

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

    try {
        int t = inf.readInt(1, 10000, "t");
        int k = inf.readInt(1, 10, "k");
        long long c = inf.readLong(2, 2000000000LL, "c");

        query_limit = 1LL * t * k;
        log_metrics();

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

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

        for (int game = 0; game < t; game++) {
            long long hidden = inf.readLong(1, c, "x");

            while (true) {
                string op;
                if (!readToken(op)) finish(_pe, "Unexpected EOF from contestant.");

                if (op == "?") {
                    string sb;
                    if (!readToken(sb)) finish(_pe, "Missing base after '?'.");

                    long long b;
                    if (!parseLongLongStrict(sb, b)) finish(_pe, "Base is not an integer.");
                    if (b < 2 || b > c) finish(_pe, "Base out of range.");

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

                    long long ans = (hidden < b) ? -1 : digitSumBase(hidden, b);
                    cout << ans << "\n";
                    cout.flush();
                } else if (op == "!") {
                    string sx;
                    if (!readToken(sx)) finish(_pe, "Missing number after '!'.");

                    long long guess;
                    if (!parseLongLongStrict(sx, guess)) finish(_pe, "Guess is not an integer.");
                    if (guess < 1 || guess > c) finish(_pe, "Guess out of range.");

                    int ok = (guess == hidden) ? 1 : 0;
                    cout << ok << "\n";
                    cout.flush();

                    if (!ok) finish(_wa, "Wrong guess.");
                    break;
                } else {
                    finish(_pe, "Invalid operation token (expected '?' or '!').");
                }
            }
        }

        finish(_ok, "All games solved.");
    } catch (const std::exception& e) {
        finish(_pe, string("Exception: ") + e.what());
    } catch (...) {
        finish(_pe, "Unknown exception.");
    }
}

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

static long long clampLL(long long x, long long lo, long long hi) {
    if (x < lo) return lo;
    if (x > hi) return hi;
    return x;
}

static long long powLLBounded(long long base, int exp, long long limit) {
    __int128 v = 1;
    for (int i = 0; i < exp; i++) {
        v *= (__int128)base;
        if (v > (__int128)limit) return limit + 1;
    }
    return (long long)v;
}

static long long genStructuredX(long long c) {
    long long sq = (long long)sqrt((long double)c);
    sq = max(2LL, min(sq, c));

    int kind = rnd.next(1, 4);
    if (kind == 1) {
        long long a = rnd.next(2LL, sq);
        long long b = rnd.next(2LL, sq);
        __int128 prod = (__int128)a * (__int128)b;
        long long x;
        if (prod <= (__int128)c) {
            x = (long long)prod;
        } else {
            long long m = a;
            if (m <= 0) m = 2;
            x = (c / m) * m;
            if (x <= 0) x = 1;
            if (x > c) x = c;
        }
        return clampLL(x, 1, c);
    } else if (kind == 2) {
        for (int tries = 0; tries < 40; tries++) {
            long long base = rnd.next(2LL, min(1000000LL, c));
            int exp = rnd.next(2, 6);
            long long x = powLLBounded(base, exp, c);
            if (1 <= x && x <= c) return x;
        }
        long long base = rnd.next(2LL, min(50000LL, c));
        long long x = base * base;
        if (x < 1) x = 1;
        if (x > c) x = c;
        return x;
    } else if (kind == 3) {
        int bits = rnd.next(1, 31);
        long long x = (bits == 31) ? (long long)INT_MAX : ((1LL << bits) - 1);
        if (x > c) x = c;
        if (x < 1) x = 1;
        return x;
    } else {
        long long m = rnd.next(2LL, min(1000000LL, c));
        long long x = (c / m) * m;
        if (x == 0) x = m;
        x = clampLL(x, 1, c);
        if (rnd.next(0, 1) && x - m >= 1) x -= m;
        if (rnd.next(0, 1) && x + m <= c) x += m;
        return clampLL(x, 1, c);
    }
}

static long long genRandomX(long long c) {
    int bucket = rnd.next(1, 100);

    if (bucket <= 10) {
        long long hi = min(c, 1000000LL);
        return rnd.next(1LL, hi);
    } else if (bucket <= 30) {
        long long lo = max(1LL, c / 3);
        long long hi = min(c, (2LL * c) / 3);
        if (lo > hi) swap(lo, hi);
        return rnd.next(lo, hi);
    } else if (bucket <= 80) {
        long long lo = max(1LL, c - 10000000LL);
        return rnd.next(lo, c);
    } else {
        return genStructuredX(c);
    }
}

static vector<long long> craftedNon(int seed, long long c) {
    vector<long long> v;
    auto push = [&](long long x) {
        x = clampLL(x, 1, c);
        v.push_back(x);
    };

    if (seed == 1) {
        push(1);
        push(2);
        push(3);
        push(4);
        push(5);
        push(6);
        push(7);
        push(8);
        push(9);
        push(10);
        push(42);
        push(1000000);
        push(999999937LL);
        push(1073741824LL);
        push(1162261467LL);
        push(c - 2);
        push(c - 1);
        push(c);
    } else if (seed == 2) {
        push(c);
        push(c - 1);
        push(c - 2);
        push(c - 3);
        push(c / 2);
        push(c / 2 + 1);
        push(max(1LL, c - 1000));
        push(max(1LL, c - 999));
        push(1073741824LL);
        push(536870912LL);
        push(268435456LL);
        push(1162261467LL);
        push(3486784401LL);
        push(1999999943LL);
        push(1999999999LL);
    } else {
        push(42);
        push(1);
        push(2);
        push(3);
        push(100);
        push(999);
        push(1024);
        push(65536);
        push(1000000);
        push(123456789);
        push(987654321);
        push(999999996);
        push(1000000000);
        push(1000000001);
        push(1073741824LL);
        push(1162261467LL);
        push(1999999943LL);
        push(c - 1);
        push(c);
    }

    for (auto &x : v) x = clampLL(x, 1, c);
    return v;
}

static vector<pair<long long,long long>> craftedAdp(int seed, long long c) {
    vector<pair<long long,long long>> v;
    auto push = [&](long long l, long long r) {
        l = clampLL(l, 1, c);
        r = clampLL(r, 1, c);
        if (l > r) swap(l, r);
        v.push_back({l, r});
    };

    if (seed == 1) {
        push(1, 1);
        push(2, 2);
        push(1, 2);
        push(1, 3);
        push(c, c);
        push(c - 1, c);
        push(1, c);
        push(max(1LL, c - 1000), c);
        push(1, min(c, 1000000LL));
        push(42, 42);
        push(1000000, 1000000);
        push(1073741824LL, 1073741824LL);
    } else if (seed == 2) {
        push(1, c);
        push(1, c);
        push(max(1LL, c - 10000000LL), c);
        push(max(1LL, c - 10000000LL), c);
        push(1, min(c, 1000000LL));
        push(c / 2, min(c, c / 2 + 1000));
        push(max(1LL, c / 2 - 1000), c / 2);
        push(c - 1, c);
        push(c, c);
    } else {
        push(1, c);
        push(1, c);
        push(1, min(c, 1000000LL));
        push(max(1LL, c - 10000000LL), c);
        push(42, 43);
        push(999999937LL, 999999937LL);
        push(1073741824LL, 1073741824LL);
        push(1162261467LL, 1162261467LL);
        push(c - 2, c);
    }

    return v;
}

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

    string mode = opt<string>("mode", "non");
    int tOpt = opt<int>("t", 10000);
    int k = opt<int>("k", 3);
    long long c = opt<long long>("c", 2000000000LL);

    ensuref(mode == "non" || mode == "adp", "Unknown --mode (expected non/adp).");
    ensuref(1 <= tOpt && tOpt <= 10000, "t out of range.");
    ensuref(1 <= k && k <= 10, "k out of range.");
    ensuref(2 <= c, "c too small.");

    int seed = 0;
    if (argc >= 2) seed = atoi(argv[1]);
    int t = tOpt;

    cout << t << " " << k << " " << c << "\n";

    if (mode == "non") {
        vector<long long> xs;
        if (seed >= 1 && seed <= 3) {
            xs = craftedNon(seed, c);
        }

        for (int i = 0; i < t; i++) {
            long long x;
            if (seed >= 1 && seed <= 3) {
                x = xs[i % (int)xs.size()];
            } else {
                if (i == 0) x = 1;
                else if (i == 1) x = c;
                else if (i == 2) x = max(1LL, c - 1);
                else if (i == 3) x = clampLL(1073741824LL, 1, c);
                else if (i == 4) x = clampLL(1162261467LL, 1, c);
                else {
                    x = genRandomX(c);
                    if (rnd.next(1, 100) <= 75) {
                        long long lo = max(1LL, c - 20000000LL);
                        x = rnd.next(lo, c);
                    }
                }
            }
            x = clampLL(x, 1, c);
            cout << x << "\n";
        }
    } else {
        vector<pair<long long,long long>> segs;
        if (seed >= 1 && seed <= 3) {
            segs = craftedAdp(seed, c);
        }

        for (int i = 0; i < t; i++) {
            long long L, R;
            if (seed >= 1 && seed <= 3) {
                auto pr = segs[i % (int)segs.size()];
                L = pr.first;
                R = pr.second;
            } else {
                int bucket = rnd.next(1, 100);
                if (i < 2 || bucket <= 70) {
                    L = 1;
                    R = c;
                } else if (bucket <= 85) {
                    L = max(1LL, c - 20000000LL);
                    R = c;
                } else if (bucket <= 95) {
                    L = 1;
                    R = min(c, 1000000LL);
                } else {
                    long long center = genRandomX(c);
                    long long w = rnd.next(0LL, 2000LL);
                    L = clampLL(center - w, 1, c);
                    R = clampLL(center + w, 1, c);
                    if (L > R) swap(L, R);
                }
            }
            L = clampLL(L, 1, c);
            R = clampLL(R, 1, c);
            if (L > R) swap(L, R);
            cout << L << " " << R << "\n";
        }
    }

    return 0;
}


This is an interactive problem.

There is a hidden permutation of $n$ . Recall that a permutation of $n$ is a sequence where each integer from $1$ to $n$ (both inclusive) appears exactly once. Piggy wants to unravel the permutation with some queries.

Each query must consist of a sequence (not necessarily a permutation) with $n$ integers ranging from 1 to $n$ (both inclusive). Each query is answered with an integer $x$ , indicating the number of the positions where the corresponding element in Piggy’s query sequence matches that of the hidden permutation. For example, if the hidden permutation is $\{ 1 , 3 , 4 , 2 , 5 \}$ and the sequence Piggy asks is $\{ 2 , 3 , 5 , 2 , 5 \}$ , he’ll receive 3 as the answer.

As Piggy is busy recently, he gives this problem to you. Find the permutation with no more than 6666 queries.

# Input

There is only one test case in each test file.

The first line of the input contains an integer $n$ ( $1 \leq n \leq 1 0 ^ { 3 }$ ) indicating the length of the hidden permutation.

# Interaction Protocol

To ask a query, output one line. First output 0 followed by a space, then print a sequence of $n$ integers ranging from 1 to $n$ separated by a space. After flushing your output, your program should read a single integer $x$ indicating the answer to your query.

If you want to guess the permutation, output one line. First output 1 followed by a space, then print a permutation of $n$ separated by a space. After flushing your output, your program should exit immediately.

Note that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.

To flush your output, you can use:

• fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.
• System.out.flush() in Java.
• stdout.flush() in Python.

# Example

standard input	standard output

5	031322

3	031522

4

2	035444

	131524

# Note

Please note that if you receive a Time Limit Exceeded verdict, it is possible that your query is invalid or the number of queries exceeds the limit.

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

static long long queries = 0;
static long long query_limit = 6666;
static const long long HARD_CAP = 200000;

static int n;
static vector<int> hidden_p;

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

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    n = inf.readInt(1, 1000, "n");
    hidden_p.resize(n);
    for (int i = 0; i < n; i++) {
        hidden_p[i] = inf.readInt(1, n, format("p[%d]", i + 1).c_str());
    }

    cout << n << endl;

    while (true) {
        string token;
        if (!(cin >> token)) {
            finish(_pe, "Unexpected EOF while reading query type");
        }

        bool is_query = (token == "0" || token == "?");
        bool is_guess = (token == "1" || token == "!");

        if (!is_query && !is_guess) {
            finish(_pe, format("Expected '0' or '1', found '%s'", token.c_str()));
        }

        if (is_query) {
            queries++;

            if (queries % 50 == 0) {
                log_metrics();
            }

            if (queries > HARD_CAP) {
                finish(_pe, "Hard query limit exceeded");
            }

            vector<int> q(n);
            for (int i = 0; i < n; i++) {
                if (!(cin >> q[i])) {
                    finish(_pe, "Unexpected EOF while reading query sequence");
                }

                if (q[i] < 1 || q[i] > n) {
                    finish(_pe, format("Query element %d out of range [1, %d]", q[i], n));
                }
            }

            int matches = 0;
            for (int i = 0; i < n; i++) {
                if (q[i] == hidden_p[i]) {
                    matches++;
                }
            }

            cout << matches << endl;

        } else {

            vector<int> g(n);
            for (int i = 0; i < n; i++) {
                if (!(cin >> g[i])) {
                    finish(_pe, "Unexpected EOF while reading guess sequence");
                }

                if (g[i] < 1 || g[i] > n) {
                    finish(_pe, format("Guess element %d out of range [1, %d]", g[i], n));
                }
            }

            if (g == hidden_p) {
                finish(_ok, format("Correct! Solved in %lld queries.", queries));
            } else {
                finish(_wa, "Wrong guess.");
            }
        }
    }

    return 0;
}

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

    if (n == 0) {

        long long seed_val = -1;
        try {
            seed_val = stoll(string(argv[1]));
        } catch (...) {
            seed_val = -1;
        }

        if (seed_val == 1) n = 1;
        else if (seed_val == 2) n = 1000;
        else if (seed_val == 3) n = 2;
        else if (seed_val == 4) n = 3;
        else if (seed_val == 5) n = 10;
        else {

            int t = rnd.next(1, 100);
            if (t <= 5) n = rnd.next(1, 10);
            else if (t <= 15) n = rnd.next(11, 100);
            else n = rnd.next(900, 1000);
        }
    }

    cout << n << endl;

    if (mode == "non") {

        vector<int> p;
        int type = rnd.next(1, 100);

        if (n > 1 && type <= 20) {
            p.resize(n);
            iota(p.begin(), p.end(), 1);

            if (type <= 5) {

            } else if (type <= 10) {

                reverse(p.begin(), p.end());
            } else if (type <= 15) {

                int shift = rnd.next(1, n - 1);
                rotate(p.begin(), p.begin() + shift, p.end());
            } else {

                int i = rnd.next(0, n - 1);
                int j = rnd.next(0, n - 1);
                while (i == j) j = rnd.next(0, n - 1);
                swap(p[i], p[j]);
            }
        } else {

            p = rnd.perm(n, 1);
        }

        println(p);
    }
    else {

    }

    return 0;
}


B. Glad to see you!

This is an interactive problem. In the output section below you will see the information about flushing the output.

On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.

In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of *n* dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to *n*. After a little thought, the girl ordered exactly *k* different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.

The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers *x* and *y* (1 ≤ *x*, *y* ≤ *n*). After that Noora chooses some dish *a* for the number *x* such that, at first, *a* is among the dishes Noora ordered (*x* can be equal to *a*), and, secondly, the value ![](https://espresso.codeforces.com/e5a4a1705bc256e413564795cc8b70857f0ae44c.png) is the minimum possible. By the same rules the girl chooses dish *b* for *y*. After that Noora says «TAK» to Leha, if ![](https://espresso.codeforces.com/a65cb6a9b614699e12e529560e2d39ffa39127db.png), and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.

Help Leha to solve this problem!

Input

There are two numbers *n* and *k* (2 ≤ *k* ≤ *n* ≤ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.

Output

If you want to provide an answer, output a string of the form 2 *x* *y* (1 ≤ *x*, *y* ≤ *n*, *x* ≠ *y*), if you think the dishes *x* and *y* was among dishes ordered by Noora. After that, flush the output and terminate your program.

Interaction

While helping Leha, you can ask queries to Noora no more than 60 times. Each query should be printed in it's own line and have the form 1 *x* *y* (1 ≤ *x*, *y* ≤ *n*). You have to both print the end-of-line character and flush the output. After flushing you should read the answer for this query from input.

After each query jury's program will print one line «TAK» or «NIE» (without quotes) in input stream depending on the girl's answer.

To flush you can use (just after printing an integer and end-of-line):

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

Example

Input

```
3 2
NIE
TAK
NIE
TAK
TAK
TAK
```

Output

```
1 1 2
1 2 1
1 1 3
1 3 1
1 2 3
1 3 2
2 2 3
```

Note

There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (*x* = 1), then she'll choose the second dish (*a* = 2) as the dish with the minimum value ![](https://espresso.codeforces.com/e5a4a1705bc256e413564795cc8b70857f0ae44c.png). For the second (*x* = 2) and the third (*x* = 3) dishes themselves will be optimal, because in that case ![](https://espresso.codeforces.com/79add195d023131e992b60a354fec89501759e75.png).

Let Leha asks Noora about the next couple of dishes:

* *x* = 1, *y* = 2, then he'll recieve «NIE» answer, because |1 - 2| > |2 - 2|
* *x* = 2, *y* = 1, then he'll recieve «TAK» answer, because |2 - 2| ≤ |1 - 2|
* *x* = 1, *y* = 3, then he'll recieve «NIE» answer, because |1 - 2| > |3 - 3|
* *x* = 3, *y* = 1, then he'll recieve «TAK» answer, because |3 - 3| ≤ |1 - 2|
* *x* = 2, *y* = 3, then he'll recieve «TAK» answer, because |2 - 2| ≤ |3 - 3|
* *x* = 3, *y* = 2, then he'll recieve «TAK» answer, because |3 - 3| ≤ |2 - 2|

According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static const long long QUERY_LIMIT = 60;

static const long long HARD_QUERY_CAP = 2000;

static long long queries = 0;
static long long query_limit = QUERY_LIMIT;
static bool finished_mode = false;

static void log_metrics() {

    tout << "queries=" << queries << endl;
    tout << "query_limit=" << query_limit << endl;
}

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

static void final_log() {
    if (!finished_mode) {
        log_metrics();
    }
}

int get_min_dist(int p, const vector<int>& s) {
    auto it = lower_bound(s.begin(), s.end(), p);
    int d = 2000000000;

    if (it != s.end()) {
        d = min(d, abs(p - *it));
    }

    if (it != s.begin()) {
        d = min(d, abs(p - *prev(it)));
    }
    return d;
}

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

    registerInteraction(argc, argv);
    atexit(final_log);

    int n = inf.readInt();
    int k = inf.readInt();

    vector<int> s(k);
    for (int i = 0; i < k; ++i) {
        s[i] = inf.readInt();
    }

    sort(s.begin(), s.end());

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

    log_metrics();

    while (true) {
        string token;

        if (!(cin >> token)) {

            finish(_wa, "Unexpected EOF: expected query ('1'/'?') or answer ('2'/'!')");
        }

        bool is_query = (token == "1" || token == "?");
        bool is_answer = (token == "2" || token == "!");

        if (is_query) {
            int x, y;
            if (!(cin >> x >> y)) {
                finish(_wa, "Malformed query parameters: expected 2 integers");
            }

            if (x < 1 || x > n || y < 1 || y > n) {
                finish(_pe, format("Query coordinates out of bounds: x=%d, y=%d, n=%d", x, y, n));
            }

            queries++;
            if (queries > HARD_QUERY_CAP) {
                finish(_pe, "Hard query limit exceeded (> 2000)");
            }

            if (queries % 10 == 0) {
                log_metrics();
            }

            int dist_x = get_min_dist(x, s);
            int dist_y = get_min_dist(y, s);

            if (dist_x <= dist_y) {
                cout << "TAK" << endl;
            } else {
                cout << "NIE" << endl;
            }

        } else if (is_answer) {
            int x, y;
            if (!(cin >> x >> y)) {
                finish(_wa, "Malformed answer parameters: expected 2 integers");
            }

            bool x_in_s = binary_search(s.begin(), s.end(), x);
            bool y_in_s = binary_search(s.begin(), s.end(), y);

            if (x != y && x_in_s && y_in_s) {
                finish(_ok, format("Correct! Found %d and %d. queries=%lld", x, y, queries));
            } else {
                string msg = "Incorrect answer. ";
                if (x == y) msg += format("x and y must be distinct (got %d). ", x);
                if (!x_in_s) msg += format("Dish %d is not in the hidden set. ", x);
                if (!y_in_s) msg += format("Dish %d is not in the hidden set. ", y);
                finish(_wa, msg);
            }

        } else {

            finish(_pe, format("Protocol error: expected '1', '2', '?', or '!', but got '%s'", token.c_str()));
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

static long long queries = 0;
static long long query_limit = 60;

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 n, k;

vector<vector<int>> candidates;

long long get_dist(int p, const vector<int>& S) {
    auto it = lower_bound(S.begin(), S.end(), p);
    long long d = 2000000000LL;
    if (it != S.end()) {
        d = min(d, (long long)(*it) - p);
    }
    if (it != S.begin()) {
        d = min(d, (long long)p - *prev(it));
    }
    return d;
}

bool eval_query(const vector<int>& S, int x, int y) {
    long long dx = get_dist(x, S);
    long long dy = get_dist(y, S);
    return dx <= dy;
}

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

    n = inf.readInt(2, 100000, "n");
    k = inf.readInt(2, n, "k");

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

    inf.skipBlanks();
    if (!inf.eof()) {

        vector<int> S(k);
        for(int i=0; i<k; ++i) S[i] = inf.readInt(1, n, "s_i");
        sort(S.begin(), S.end());
        candidates.push_back(S);
    } else {

        mt19937 rng(n * 239 + k * 17 + 58);

        int max_candidates = 1000;
        if (n > 5000) max_candidates = 300;
        if (n > 50000) max_candidates = 100;

        auto add_cand = [&](vector<int> s) {
            sort(s.begin(), s.end());
            s.erase(unique(s.begin(), s.end()), s.end());

            if ((int)s.size() < k) {

                vector<bool> present(n + 1, false);
                for(int x : s) present[x] = true;
                for(int i=1; i<=n && (int)s.size() < k; ++i) {
                    if(!present[i]) {
                        s.push_back(i);
                        present[i] = true;
                    }
                }
                sort(s.begin(), s.end());
            }
            candidates.push_back(s);
        };

        {
            vector<int> s;
            for(int i=1; i<=k; ++i) s.push_back(i);
            add_cand(s);
        }

        {
            vector<int> s;
            for(int i=0; i<k; ++i) s.push_back(n-i);
            add_cand(s);
        }

        if (k >= 2) {
             vector<int> s;
             s.push_back(1); s.push_back(n);
             while((int)s.size() < k) s.push_back(rng() % n + 1);
             add_cand(s);
        }

        {
            vector<int> s;
            int start = max(1, n/2 - k/2);
            for(int i=0; i<k; ++i) if(start+i <= n) s.push_back(start+i);
            add_cand(s);
        }

        while ((int)candidates.size() < max_candidates) {
             vector<int> s;
             if (k * 2 < n) {

                 while((int)s.size() < k) s.push_back(rng() % n + 1);
             } else {

                 vector<int> excl;
                 while((int)excl.size() < n - k) excl.push_back(rng() % n + 1);
                 sort(excl.begin(), excl.end());
                 excl.erase(unique(excl.begin(), excl.end()), excl.end());

                 int ptr = 0;
                 for(int i=1; i<=n; ++i) {
                     if(ptr < (int)excl.size() && excl[ptr] == i) {
                         ptr++;
                     } else {
                         s.push_back(i);
                     }
                 }

                 if((int)s.size() > k) s.resize(k);
             }
             add_cand(s);
        }
    }

    while (true) {

        if (queries > max(200000LL, 10 * query_limit)) {
            finish(_pe, "Too many queries (hard cap exceeded)");
        }

        string type;
        cin >> type;
        if (cin.fail()) finish(_pe, "Unexpected EOF while reading query type");

        bool is_ans = (type == "2" || type == "!");
        if (!is_ans && type != "1" && type != "?") {
            finish(_pe, format("Invalid query type: '%s'. Expected '1' or '2'.", type.c_str()));
        }

        int x, y;
        cin >> x >> y;
        if (cin.fail()) finish(_pe, "Unexpected EOF while reading query arguments");

        if (x < 1 || x > n || y < 1 || y > n) {
            finish(_wa, format("Arguments out of range: %d %d", x, y));
        }
        if (is_ans && x == y) {
            finish(_wa, format("Final answer must contain distinct dishes, got: %d %d", x, y));
        }

        if (is_ans) {

            for (const auto& S : candidates) {
                bool has_x = binary_search(S.begin(), S.end(), x);
                bool has_y = binary_search(S.begin(), S.end(), y);
                if (!has_x || !has_y) {
                    finish(_wa, format("Wrong Answer: guess {%d, %d} is incorrect for a consistent hidden set", x, y));
                }
            }

            finish(_ok, format("Correct! Found dishes {%d, %d}", x, y));
        } else {

            queries++;

            int votes_tak = 0;
            int votes_nie = 0;
            for (const auto& S : candidates) {
                if (eval_query(S, x, y)) votes_tak++;
                else votes_nie++;
            }

            bool ans_tak = (votes_tak >= votes_nie);
            cout << (ans_tak ? "TAK" : "NIE") << endl;

            int head = 0;
            for (int i = 0; i < (int)candidates.size(); ++i) {
                if (eval_query(candidates[i], x, y) == ans_tak) {
                    if (head != i) candidates[head] = move(candidates[i]);
                    head++;
                }
            }
            candidates.resize(head);

            if (candidates.empty()) {

                finish(_wa, "Interactor Error: No consistent hidden sets left.");
            }
        }
    }
}

#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 n_opt = opt<int>("n", -1);
    int k_opt = opt<int>("k", -1);

    int seed_val = atoi(argv[1]);

    int n;
    if (n_opt != -1) {
        n = n_opt;
    } else {
        if (seed_val == 1) n = 3;
        else if (seed_val == 2) n = 10;
        else if (seed_val == 3) n = 100000;
        else if (seed_val <= 10) n = rnd.next(10, 100);
        else n = rnd.next(90000, 100000);
    }

    int k;
    if (k_opt != -1) {
        k = k_opt;
    } else {
        if (seed_val == 1) k = 2;
        else if (seed_val == 2) k = 5;
        else if (seed_val == 3) k = 2;
        else if (seed_val == 4) k = n;
        else {
            int type = rnd.next(1, 100);
            if (type <= 30) k = 2;
            else if (type <= 50) k = min(n, rnd.next(3, 20));
            else if (type <= 80) k = rnd.next(2, n);
            else k = rnd.next(max(2, n - 50), n);
        }
    }

    n = max(2, min(n, 100000));
    k = max(2, min(k, n));

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

    if (mode == "non") {

        vector<int> s;

        bool pattern_used = false;

        if (!pattern_used && seed_val == 3 && k == 2) {
            s = {1, n};
            pattern_used = true;
        }

        if (!pattern_used && seed_val == 5 && k == 2) {
            if (n >= 2) {
                s = {n / 2, n / 2 + 1};
                pattern_used = true;
            }
        }

        if (!pattern_used && seed_val == 6 && k == 2) {
            s = {1, 2};
            pattern_used = true;
        }

        if (!pattern_used) {

            s = rnd.distinct(k, n);
            for (int &x : s) x++;
        }

        sort(s.begin(), s.end());
        println(s);
    } else {

    }

    return 0;
}


This is an interactive problem.

In this problem, you need to come up with a strategy for a cooperative game. This game is played by two players. Each player receives 5 cards. Each card has a random integer between 1 and 100 on it. It is guaranteed that all numbers on cards are distinct.

The goal of the game is to play a card with a minimal number on it out of all 10 cards dealt to the players before any other card. The problem is that each player can only see their own cards and cannot communicate with another player in any way.

The game consists of 5 turns. During each turn, players simultaneously make a move. Each player can either play their smallest card or do nothing. If on some turn the smallest card is played, and no other card is played on or before that turn, players win. If two cards are played at the same turn or if after all 5 turns, no card is still played, players lose.

Players cannot communicate, so a strategy for the game should only be based on 5 cards that the player has. You can describe a strategy as five numbers $0.0 \le p_i \le 1.0, \sum_{i=1}^{5}p_i \le 1$, where $p_i$ — the probability of playing the player's smallest card in their hand on $i$-th turn. If you know the cards dealt to the players, and the strategies that players choose, you can compute the probability of winning by a simple formula.

You will be given $n=1000$ randomly generated hands of 5 cards. You need to generate a strategy for each of the hands to maximize the probability of winning. After the judge program receives all $n$ strategies, it generates all possible valid pairs of those hands (pairs which have the same numbers are discarded), and computes a probability of winning based on two strategies provided by your program.

To ensure that answers for different hands are independent, you must output a strategy for a hand and flush the standard output before reading information about the next hand.

If the average probability of winning a game is more than 85% over all valid pairs of hands, the test is considered passed. This problem contains the sample test and $20$ randomly generated tests with $n = 1000$.

Input

The first line contains one integer $n$ — the number of hands. It is guaranteed that $n = 1000$ for all cases except the first sample case.

Each of the next $n$ lines contains 5 numbers $a_i$ ($1 \le a_i \le 100, a_i < a_{i+1}$) — the cards in the hand. It is guaranteed that each possible set of 5 cards has an equal probability of being chosen.

Output

For each of the $n$ hands you need to output 5 numbers $0.0 \le p_i \le 1.0, \sum_{i=1}^{5}p_i \le 1$, where $p_i$ — probability of playing the smallest card on $i$-th turn.

Example

Input

```
2
2 12 27 71 100

22 29 39 68 90
```

Output

```
0.8 0.2 0.0 0.0 0.0

0.0 0.2 0.2 0.2 0.3
```

Note

In the example test there is only one valid pair of hands. The winning probability for the example output is equal to $0.8 + 0.2 \cdot (1 - 0.2) = 0.96$. Also note that the second player will not play a card at all with probability 0.1.

#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 string fmt_double(double x) {
    char buf[64];
    sprintf(buf, "%.5f", x);
    return string(buf);
}

struct Hand {
    vector<int> cards;
    vector<double> probs;
};

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int n = inf.readInt();
    query_limit = n;

    log_metrics();

    cout << n << endl;

    vector<Hand> hands(n);

    for (int i = 0; i < n; ++i) {
        hands[i].cards.resize(5);
        for (int j = 0; j < 5; ++j) {
            hands[i].cards[j] = inf.readInt();
        }

        for (int j = 0; j < 5; ++j) {
            cout << hands[i].cards[j] << (j == 4 ? "" : " ");
        }
        cout << endl;

        hands[i].probs.resize(5);
        double sum_p = 0.0;
        for (int j = 0; j < 5; ++j) {

            if (!(cin >> hands[i].probs[j])) {
                finish(_pe, "Failed to read probability " + to_string(j+1) + " for hand " + to_string(i+1));
            }

            if (hands[i].probs[j] < -1e-9 || hands[i].probs[j] > 1.0 + 1e-9) {
                finish(_wa, "Probability must be in [0, 1] for hand " + to_string(i+1));
            }

            if (hands[i].probs[j] < 0) hands[i].probs[j] = 0;
            if (hands[i].probs[j] > 1) hands[i].probs[j] = 1;

            sum_p += hands[i].probs[j];
        }

        if (sum_p > 1.0 + 1e-7) {
            finish(_wa, "Sum of probabilities exceeds 1.0 for hand " + to_string(i+1));
        }

        queries++;

        if (queries % 10 == 0) {
            log_metrics();
        }
    }

    double total_win_prob = 0.0;
    long long valid_pairs = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {

            bool disjoint = true;
            int p1 = 0, p2 = 0;
            const vector<int>& c1 = hands[i].cards;
            const vector<int>& c2 = hands[j].cards;

            while (p1 < 5 && p2 < 5) {
                if (c1[p1] == c2[p2]) {
                    disjoint = false;
                    break;
                }
                if (c1[p1] < c2[p2]) p1++;
                else p2++;
            }

            if (disjoint) {
                valid_pairs++;

                int min_i = c1[0];
                int min_j = c2[0];

                const Hand* winner = (min_i < min_j) ? &hands[i] : &hands[j];
                const Hand* loser  = (min_i < min_j) ? &hands[j] : &hands[i];

                double prob = 0.0;
                double loser_cum = 0.0;
                for (int k = 0; k < 5; ++k) {
                    loser_cum += loser->probs[k];
                    if (loser_cum > 1.0) loser_cum = 1.0;

                    prob += winner->probs[k] * (1.0 - loser_cum);
                }
                total_win_prob += prob;
            }
        }
    }

    if (valid_pairs == 0) {

        finish(_wa, "No valid disjoint pairs found (unexpected)");
    }

    double avg = total_win_prob / valid_pairs;

    if (avg > 0.85) {
        finish(_ok, "Passed, average winning probability = " + fmt_double(avg));
    } else {
        finish(_wa, "Average winning probability too low: " + fmt_double(avg) + " <= 0.85");
    }

    return 0;
}

#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 n = opt<int>("n", 1000);

    if (string(argv[1]) == "1") {
        cout << "2\n";
        cout << "2 12 27 71 100\n";
        cout << "22 29 39 68 90\n";
        return 0;
    }

    cout << n << "\n";
    for (int i = 0; i < n; ++i) {

        vector<int> hand = rnd.distinct(5, 100);

        for (int &card : hand) {
            card++;
        }

        sort(hand.begin(), hand.end());

        for (int j = 0; j < 5; ++j) {
            cout << hand[j] << (j == 4 ? "" : " ");
        }
        cout << "\n";
    }

    return 0;
}


Carl has $n$ coins of various colors, and he would like to sort them into piles. The coins are labeled $1,2,\ldots,n$, and each coin is exactly one of red, green, or blue. He would like to sort the coins into three different piles so one pile contains all red coins, one pile contains all green coins, and one pile contains all blue coins.

Unfortunately, Carl is colorblind, so this task is impossible for him. Luckily, he has a friend who can take a pair of coins and tell Carl if they are the same color or not. Using his friend, Carl believes he can now sort the coins. The order of the piles doesn't matter, as long as all same colored coins are in the one pile, and no two different colored coins are in the same pile.

His friend will answer questions about multiple pairs of coins in batches, and will answer about all of those pairs in parallel. Each coin should be in at most one pair in each batch. The same coin can appear in different batches.

Carl can use only $7$ batches. Help him find the piles of coins after sorting.

Interaction

You will be given multiple test cases. The first line contains an integer $t$ $(1 \leq t \leq 5$) — the number of test cases.

The first line of each test case contains one integer $n$ ($1 \leq n \leq 10^5$) — the number of coins. If you read in a value of $-1$ here, that means that you printed an invalid answer in the previous case and exit immediately to avoid getting other verdicts.

To ask a question, print "Q $k\ x_1\ y_1\ \ldots\ x_k\ y_k$" ($1 \leq k \leq n/2, 1 \leq x_i,y_i \leq n, x_i \neq y_i$). $k$ denotes the number of pairs in the batch, and $x_i, y_i$ denote the $i$-th pair of coins in the batch. A coin can only appear at most once in a batch. All $x_i$ and $y_i$ should be distinct.

The judge will respond with a bitstring of length $k$, where the $i$-th character is "1" if $x_i$ and $y_i$ are the same color, and "0" otherwise. The judge will respond with $-1$ if you ever ask an invalid query. Make sure to exit immediately to avoid getting other verdicts.

When you are ready to answer, print four lines.

The first line contains "A $k_1\ k_2\ k_3$" ($0 \leq k_1,k_2,k_3$ and $k_1+k_2+k_3 = n$). These denote the sizes of the three piles.

The next line has $k_1$ integers, the labels of the coins in the first pile.

The next line has $k_2$ integers, the labels of the coins in the second pile.

The next line has $k_3$ integers, the labels coins in the third pile.

Each coin must appear in exactly one pile.

You may only ask at most $7$ batches per test case.

After printing a query and the answer do not forget to output 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 documentation for other languages.

Example

Input

```
3
3
1
1
1
3
1
0
0
6
000
010
100
001
000
```

Output

```
Q 1 1 2
Q 1 2 3
Q 1 1 3
A 3 0 0
1 2 3

Q 1 1 3
Q 1 2 3
Q 1 1 2
A 2 0 1
1 3

2
Q 3 1 2 3 4 5 6
Q 3 1 3 2 5 4 6
Q 3 1 4 2 6 3 5
Q 3 1 5 2 4 3 6
Q 3 1 6 2 3 4 5
A 2 2 2
1 4
2 5
3 6
```

Note

In the example, there are three test cases.

In the first test case, there are three coins. We ask about the pairs $(1,2)$, $(2,3)$, and $(1,3)$ in different batches and get that they are all the same color. Thus, we know all the coins are the same color, so we can put them all in one pile. Note that some piles can be empty and those are denoted with an empty line.

In the second test case, there are three coins again. This time, we only get that $(1,3)$ are the same and $(1,2)$ and $(2,3)$ are different. So, one possible scenario is that coins $1$ and $3$ are red and coin $2$ is green.

In the last case, there are $6$ coins. The case shows how to ask and receive answers for multiple pairs in one batch.

#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 readTokenFromContestant(string& s) {
    s.clear();
    return (cin >> s) ? true : false;
}

static bool parseLongLongStrict(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    bool neg = false;
    if (s[i] == '+' || s[i] == '-') {
        neg = (s[i] == '-');
        i++;
    }
    if (i >= (int)s.size()) return false;
    long long val = 0;
    for (; i < (int)s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        int d = c - '0';
        if (val > (LLONG_MAX - d) / 10) return false;
        val = val * 10 + d;
    }
    out = neg ? -val : val;
    return true;
}

static long long readLLOrPE(const string& what) {
    string tok;
    if (!readTokenFromContestant(tok)) finish(_pe, "Unexpected EOF while reading " + what);
    long long x;
    if (!parseLongLongStrict(tok, x)) finish(_pe, "Malformed integer for " + what);
    return x;
}

static void printToContestantLine(const string& s) {
    cout << s << "\n";
    cout.flush();
}

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

    try {
        int t = inf.readInt(1, 5, "t");

        struct CaseData {
            int n;
            string colors;
        };
        vector<CaseData> cases;
        cases.reserve(t);

        for (int tc = 0; tc < t; tc++) {
            int n = inf.readInt(1, 100000, "n");
            string colors = inf.readToken();
            if ((int)colors.size() != n) finish(_pe, "Hidden colors length mismatch");
            for (char c : colors) {
                if (c != 'R' && c != 'G' && c != 'B') finish(_pe, "Hidden colors contain invalid character");
            }
            cases.push_back({n, colors});
        }

        query_limit = 7LL * t;
        log_metrics();

        {
            ostringstream os;
            os << t;
            printToContestantLine(os.str());
        }

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

        for (int tc = 0; tc < t; tc++) {
            const int n = cases[tc].n;
            const string& col = cases[tc].colors;

            {
                ostringstream os;
                os << n;
                printToContestantLine(os.str());
            }

            bool answered = false;
            while (!answered) {
                if (queries > hard_cap) finish(_pe, "Hard cap exceeded");
                string cmd;
                if (!readTokenFromContestant(cmd)) finish(_pe, "Unexpected EOF waiting for command");

                if (cmd == "Q") {
                    long long kll = readLLOrPE("k");
                    if (kll < 1 || kll > n / 2) {
                        printToContestantLine("-1");
                        finish(_pe, "Invalid k in query");
                    }
                    int k = (int)kll;

                    vector<int> xs(k), ys(k);
                    vector<int> used(n + 1, 0);

                    for (int i = 0; i < k; i++) {
                        long long xll = readLLOrPE("x_i");
                        long long yll = readLLOrPE("y_i");
                        if (xll < 1 || xll > n || yll < 1 || yll > n || xll == yll) {
                            printToContestantLine("-1");
                            finish(_pe, "Invalid pair endpoints");
                        }
                        int x = (int)xll, y = (int)yll;
                        if (used[x] || used[y]) {
                            printToContestantLine("-1");
                            finish(_pe, "Coin appears more than once in a batch");
                        }
                        used[x] = used[y] = 1;
                        xs[i] = x;
                        ys[i] = y;
                    }

                    queries++;

                    string ans;
                    ans.reserve(k);
                    for (int i = 0; i < k; i++) {
                        char a = col[xs[i] - 1];
                        char b = col[ys[i] - 1];
                        ans.push_back(a == b ? '1' : '0');
                    }
                    printToContestantLine(ans);
                } else if (cmd == "A") {
                    long long k1ll = readLLOrPE("k1");
                    long long k2ll = readLLOrPE("k2");
                    long long k3ll = readLLOrPE("k3");
                    if (k1ll < 0 || k2ll < 0 || k3ll < 0 || k1ll + k2ll + k3ll != n) {
                        finish(_pe, "Invalid pile sizes");
                    }
                    int k1 = (int)k1ll, k2 = (int)k2ll, k3 = (int)k3ll;

                    array<vector<int>, 3> piles;
                    piles[0].resize(k1);
                    piles[1].resize(k2);
                    piles[2].resize(k3);

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

                    auto readCoin = [&](const string& what) -> int {
                        long long vll = readLLOrPE(what);
                        if (vll < 1 || vll > n) finish(_pe, "Coin index out of range");
                        int v = (int)vll;
                        if (seen[v]) finish(_pe, "Coin appears multiple times in answer");
                        seen[v] = 1;
                        return v;
                    };

                    for (int i = 0; i < k1; i++) piles[0][i] = readCoin("pile1 coin");
                    for (int i = 0; i < k2; i++) piles[1][i] = readCoin("pile2 coin");
                    for (int i = 0; i < k3; i++) piles[2][i] = readCoin("pile3 coin");

                    for (int i = 1; i <= n; i++) {
                        if (!seen[i]) finish(_pe, "Some coin missing from answer");
                    }

                    array<char, 3> pileColor;
                    pileColor.fill(0);

                    for (int p = 0; p < 3; p++) {
                        if (piles[p].empty()) continue;
                        char pc = col[piles[p][0] - 1];
                        for (int v : piles[p]) {
                            if (col[v - 1] != pc) finish(_wa, "Pile contains mixed colors");
                        }
                        pileColor[p] = pc;
                    }

                    array<int, 256> colorToPile;
                    colorToPile.fill(-1);
                    for (int p = 0; p < 3; p++) {
                        char pc = pileColor[p];
                        if (pc == 0) continue;
                        unsigned char uc = (unsigned char)pc;
                        if (colorToPile[uc] != -1 && colorToPile[uc] != p) finish(_wa, "Same color split across piles");
                        colorToPile[uc] = p;
                    }

                    answered = true;
                } else {
                    finish(_pe, "Unknown command token");
                }
            }
        }

        string extra;
        if (readTokenFromContestant(extra)) finish(_pe, "Extra output after completing all test cases");

        finish(_ok, "OK");
    } catch (const std::exception& e) {
        finish(_pe, string("Exception: ") + e.what());
    } catch (...) {
        finish(_pe, "Unknown exception");
    }
    return 0;
}

#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 isIntegerToken(const string& s) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '-') {
        if ((int)s.size() == 1) return false;
        i = 1;
    }
    for (; i < (int)s.size(); ++i) if (!isdigit((unsigned char)s[i])) return false;
    return true;
}

static bool parseLongLong(const string& s, long long& out) {
    if (!isIntegerToken(s)) return false;
    try {
        size_t idx = 0;
        long long v = stoll(s, &idx, 10);
        if (idx != s.size()) return false;
        out = v;
        return true;
    } catch (...) {
        return false;
    }
}

static bool readTokenFromContestant(string& tok) {
    tok.clear();
    if (!(cin >> tok)) return false;
    return true;
}

static bool readLongLongFromContestant(long long& x) {
    string s;
    if (!readTokenFromContestant(s)) return false;
    return parseLongLong(s, x);
}

static vector<int> genColorsDeterministic(int n, int caseIdx0) {
    vector<int> c(n + 1, 0);
    if (n == 1) {
        c[1] = 0;
        return c;
    }
    if (n == 2) {
        c[1] = 0;
        c[2] = (caseIdx0 & 1) ? 0 : 1;
        return c;
    }
    c[1] = 0;
    c[2] = 1;
    c[3] = 2;
    long long add = 7LL * (caseIdx0 + 1);
    for (int i = 4; i <= n; ++i) c[i] = (int)((i + add) % 3);
    return c;
}

static vector<int> parseColorsString(const string& s, int n) {
    if ((int)s.size() != n) finish(_pe, "invalid hidden input: colors length mismatch");
    vector<int> c(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        char ch = s[i - 1];
        if (ch == 'R') c[i] = 0;
        else if (ch == 'G') c[i] = 1;
        else if (ch == 'B') c[i] = 2;
        else finish(_pe, "invalid hidden input: colors contain non-RGB");
    }
    return c;
}

static bool checkAnswerAgainstColors(
    int n,
    const vector<int>& col,
    const array<vector<int>, 3>& piles,
    string& err
) {
    vector<int> seen(n + 1, 0);
    for (int p = 0; p < 3; ++p) {
        for (int x : piles[p]) {
            if (x < 1 || x > n) {
                err = "answer coin out of range";
                return false;
            }
            if (seen[x]) {
                err = "answer coin repeated";
                return false;
            }
            seen[x] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (!seen[i]) {
            err = "answer missing coin";
            return false;
        }
    }

    array<int, 3> pileColor;
    pileColor.fill(-1);

    for (int p = 0; p < 3; ++p) {
        int pc = -1;
        for (int x : piles[p]) {
            int cx = col[x];
            if (pc == -1) pc = cx;
            else if (pc != cx) {
                err = "pile contains multiple colors";
                return false;
            }
        }
        pileColor[p] = pc;
    }

    for (int i = 0; i < 3; ++i) {
        if (pileColor[i] == -1) continue;
        for (int j = i + 1; j < 3; ++j) {
            if (pileColor[j] == -1) continue;
            if (pileColor[i] == pileColor[j]) {
                err = "same color split across piles";
                return false;
            }
        }
    }

    err.clear();
    return true;
}

struct HiddenCase {
    int n = 0;
    bool hasColors = false;
    string colors;
};

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

    int t = inf.readInt();
    if (t < 1 || t > 5) finish(_pe, "invalid hidden input: t out of range");

    vector<string> toks;
    while (!inf.seekEof()) toks.push_back(inf.readToken());

    vector<HiddenCase> cases;
    cases.reserve(t);

    int idx = 0;
    for (int ci = 0; ci < t; ++ci) {
        if (idx >= (int)toks.size()) finish(_pe, "invalid hidden input: missing n");
        long long nll = 0;
        if (!parseLongLong(toks[idx], nll)) finish(_pe, "invalid hidden input: n token not integer");
        idx++;
        if (nll < 1 || nll > 100000) finish(_pe, "invalid hidden input: n out of range");
        int n = (int)nll;

        HiddenCase hc;
        hc.n = n;

        if (idx < (int)toks.size()) {
            const string& nxt = toks[idx];
            bool looksLikeColors = ((int)nxt.size() == n);
            if (looksLikeColors) {
                for (char ch : nxt) {
                    if (ch != 'R' && ch != 'G' && ch != 'B') {
                        looksLikeColors = false;
                        break;
                    }
                }
            }
            if (looksLikeColors) {
                hc.hasColors = true;
                hc.colors = nxt;
                idx++;
            }
        }

        cases.push_back(std::move(hc));
    }

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

    cout << t << endl;

    for (int ci = 0; ci < t; ++ci) {
        int n = cases[ci].n;
        vector<int> col = cases[ci].hasColors ? parseColorsString(cases[ci].colors, n)
                                              : genColorsDeterministic(n, ci);

        cout << n << endl;

        while (true) {
            string cmd;
            if (!readTokenFromContestant(cmd)) finish(_pe, "unexpected EOF from contestant");

            if (cmd == "Q") {
                long long kll;
                if (!readLongLongFromContestant(kll)) {
                    cout << -1 << endl;
                    finish(_pe, "malformed query: missing k");
                }
                if (kll < 1 || kll > n / 2) {
                    cout << -1 << endl;
                    finish(_pe, "invalid query: k out of range");
                }
                int k = (int)kll;

                vector<int> xs(k), ys(k);
                vector<int> used(n + 1, 0);
                for (int i = 0; i < k; ++i) {
                    long long xll, yll;
                    if (!readLongLongFromContestant(xll) || !readLongLongFromContestant(yll)) {
                        cout << -1 << endl;
                        finish(_pe, "malformed query: missing pair endpoints");
                    }
                    if (xll < 1 || xll > n || yll < 1 || yll > n || xll == yll) {
                        cout << -1 << endl;
                        finish(_pe, "invalid query: endpoints out of range or equal");
                    }
                    int x = (int)xll, y = (int)yll;
                    if (used[x] || used[y]) {
                        cout << -1 << endl;
                        finish(_pe, "invalid query: coin appears multiple times in batch");
                    }
                    used[x] = used[y] = 1;
                    xs[i] = x;
                    ys[i] = y;
                }

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

                string resp;
                resp.reserve(k);
                for (int i = 0; i < k; ++i) {
                    resp.push_back(col[xs[i]] == col[ys[i]] ? '1' : '0');
                }
                cout << resp << endl;
            } else if (cmd == "A") {
                long long k1ll, k2ll, k3ll;
                if (!readLongLongFromContestant(k1ll) || !readLongLongFromContestant(k2ll) || !readLongLongFromContestant(k3ll)) {
                    finish(_pe, "malformed answer header");
                }
                if (k1ll < 0 || k2ll < 0 || k3ll < 0) finish(_pe, "negative pile size");
                if (k1ll + k2ll + k3ll != n) finish(_pe, "pile sizes do not sum to n");
                int k1 = (int)k1ll, k2 = (int)k2ll, k3 = (int)k3ll;

                array<vector<int>, 3> piles;
                piles[0].resize(k1);
                piles[1].resize(k2);
                piles[2].resize(k3);

                for (int i = 0; i < k1; ++i) {
                    long long v;
                    if (!readLongLongFromContestant(v)) finish(_pe, "malformed answer: missing coin in pile 1");
                    piles[0][i] = (int)v;
                }
                for (int i = 0; i < k2; ++i) {
                    long long v;
                    if (!readLongLongFromContestant(v)) finish(_pe, "malformed answer: missing coin in pile 2");
                    piles[1][i] = (int)v;
                }
                for (int i = 0; i < k3; ++i) {
                    long long v;
                    if (!readLongLongFromContestant(v)) finish(_pe, "malformed answer: missing coin in pile 3");
                    piles[2][i] = (int)v;
                }

                string err;
                if (!checkAnswerAgainstColors(n, col, piles, err)) {
                    finish(_wa, err);
                }
                break;
            } else {
                finish(_pe, "unknown command (expected Q or A)");
            }
        }
    }

    finish(_ok, "ok");
}

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

static int igcd(int a, int b) {
    while (b) {
        int t = a % b;
        a = b;
        b = t;
    }
    return a;
}

static string genBalancedShuffle(int n) {
    int c0 = n / 3;
    int c1 = n / 3;
    int c2 = n - c0 - c1;
    vector<char> v;
    v.reserve(n);
    v.insert(v.end(), c0, 'R');
    v.insert(v.end(), c1, 'G');
    v.insert(v.end(), c2, 'B');
    for (int i = n - 1; i >= 1; --i) {
        int j = rnd.next(0, i);
        swap(v[i], v[j]);
    }
    return string(v.begin(), v.end());
}

static string genMinorityScatter(int n) {
    if (n == 1) return "R";
    if (n == 2) return "RG";

    vector<char> s(n, '?');

    int maxM = min(1200, n - 2);
    int m = rnd.next(1, maxM);

    int step = rnd.next(1, n - 1);
    while (igcd(step, n) != 1) step = rnd.next(1, n - 1);
    int offset = rnd.next(0, n - 1);

    for (int i = 0; i < m; ++i) {
        int pos = (offset + (long long)i * step) % n;
        s[pos] = 'B';
    }

    int rem = n - m;
    int targetR = rem / 2;
    int targetG = rem - targetR;
    int usedR = 0, usedG = 0;

    for (int i = 0; i < n; ++i) {
        if (s[i] != '?') continue;
        bool preferR = (i & 1) == 0;
        char put;
        if ((preferR && usedR < targetR) || usedG == targetG) put = 'R';
        else put = 'G';
        s[i] = put;
        usedR += (put == 'R');
        usedG += (put == 'G');
    }

    if (count(s.begin(), s.end(), 'R') == 0) s[0] = 'R';
    if (count(s.begin(), s.end(), 'G') == 0) s[n / 2] = 'G';
    if (count(s.begin(), s.end(), 'B') == 0) s[n - 1] = 'B';

    return string(s.begin(), s.end());
}

static string genRuns(int n) {
    if (n == 1) return "R";
    if (n == 2) return "RG";

    vector<char> cols = {'R', 'G', 'B'};
    string s;
    s.reserve(n);

    int last = -1;
    while ((int)s.size() < n) {
        int c = rnd.next(0, 2);
        if (c == last) c = (c + 1 + rnd.next(0, 1)) % 3;
        int remaining = n - (int)s.size();
        int lenMax = min(remaining, 300);
        int len = rnd.next(1, lenMax);
        s.append(len, cols[c]);
        last = c;
    }

    bool hasR = s.find('R') != string::npos;
    bool hasG = s.find('G') != string::npos;
    bool hasB = s.find('B') != string::npos;
    if (!hasR) s[0] = 'R';
    if (!hasG) s[n / 2] = 'G';
    if (!hasB) s[n - 1] = 'B';

    return s;
}

static string buildColors(int n, long long seedVal) {
    if (n == 1) return "R";
    if (n == 2) {
        if ((seedVal & 1LL) == 0) return "RG";
        return "RR";
    }
    if (seedVal == 1) return string(n, 'R');
    if (seedVal == 2) return genBalancedShuffle(n);
    if (seedVal == 3) return genMinorityScatter(n);

    int kind = rnd.next(0, 2);
    if (kind == 0) return genBalancedShuffle(n);
    if (kind == 1) return genMinorityScatter(n);
    return genRuns(n);
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string mode = opt<string>("mode", "non");
    int nOpt = opt<int>("n", 100000);
    nOpt = max(1, min(100000, nOpt));

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

    int n;
    if (seedVal == 1) n = 1;
    else if (seedVal == 2) n = 100000;
    else if (seedVal == 3) n = 99991;
    else n = nOpt;

    cout << 1 << "\n";
    cout << n << "\n";

    if (mode == "non") {
        string colors = buildColors(n, seedVal);
        cout << colors << "\n";
    } else if (mode == "adp") {

    } else {

        string colors = buildColors(n, seedVal);
        cout << colors << "\n";
    }

    return 0;
}


Jury picked a polynomial $f(x) = a_0 + a_1 \cdot x + a_2 \cdot x^2 + \dots + a_k \cdot x^k$. $k \le 10$ and all $a_i$ are integer numbers and $0 \le a_i < 10^6 + 3$. It's guaranteed that there is at least one $i$ such that $a_i > 0$.

Now jury wants you to find such an integer $x_0$ that $f(x_0) \equiv 0 \mod (10^6 + 3)$ or report that there is not such $x_0$.

You can ask no more than $50$ queries: you ask value $x_q$ and jury tells you value $f(x_q) \mod (10^6 + 3)$.

Note that printing the answer doesn't count as a query.

Interaction

To ask a question, print "? $x_q$" $(0 \le x_q < 10^6 + 3)$. The judge will respond with a single integer $f(x_q) \mod (10^6 + 3)$. If you ever get a result of $−1$ (because you printed an invalid query), exit immediately to avoid getting other verdicts.

After printing a query do not forget to output 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 documentation for other languages.

When you are ready to answer, print "! $x_0$" where $x_0$ is the answer or $-1$ if there is no such $x_0$.

You can ask at most $50$ questions per test case.

Examples

Input

```
1000002

0
```

Output

```
? 0

? 1

! 1
```

Input

```
5

2

1
```

Output

```
? 2

? 1

? 0

! -1
```

Note

The polynomial in the first sample is $1000002 + x^2$.

The polynomial in the second sample is $1 + x^2$.

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

static const int MOD = 1000003;
static int k;
static vector<int> a;

static long long queries = 0;
static const long long query_limit = 50;

static void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {}
}

template<typename... Args>
static void finish(TResult verdict, const char* fmt, Args... args) {
    log_metrics();
    quitf(verdict, fmt, args...);
}

long long eval_poly(int x) {
    long long res = 0;
    for (int i = k; i >= 0; --i) {
        res = (res * x + a[i]) % MOD;
    }
    return res;
}

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

    registerInteraction(argc, argv);
    atexit(log_metrics);

    k = inf.readInt();
    a.resize(k + 1);
    for (int i = 0; i <= k; ++i) {
        a[i] = inf.readInt();
    }

    bool exists_root = false;
    for (int x = 0; x < MOD; ++x) {
        if (eval_poly(x) == 0) {
            exists_root = true;
            break;
        }
    }

    log_metrics();

    int hard_cap = 2000;

    while (true) {

        if (queries > hard_cap) {
            finish(_pe, "Hard query limit exceeded (infinite loop protection)");
        }

        string token;

        if (!(cin >> token)) {
            finish(_pe, "Unexpected end of output");
        }

        if (token == "?") {

            string x_str;
            if (!(cin >> x_str)) finish(_pe, "Unexpected EOF after '?'");

            long long x;
            try {
                size_t idx;
                x = stoll(x_str, &idx);
                if (idx != x_str.size()) throw invalid_argument("");
            } catch (...) {
                finish(_pe, "Invalid integer format for query");
            }

            if (x < 0 || x >= MOD) {

                cout << -1 << endl;
                finish(_pe, "Query x=%lld out of range [0, %d)", x, MOD);
            }

            queries++;

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

            long long val = eval_poly((int)x);
            cout << val << endl;
        }
        else if (token == "!") {

            string ans_str;
            if (!(cin >> ans_str)) finish(_pe, "Unexpected EOF after '!'");

            long long ans;
            try {
                size_t idx;
                ans = stoll(ans_str, &idx);
                if (idx != ans_str.size()) throw invalid_argument("");
            } catch (...) {
                finish(_pe, "Invalid integer format for answer");
            }

            if (ans == -1) {
                if (exists_root) {
                    finish(_wa, "Reported -1 but a root exists");
                } else {
                    finish(_ok, "Correct: no root exists");
                }
            } else {
                if (ans < 0 || ans >= MOD) {
                    finish(_wa, "Answer %lld out of range [0, %d)", ans, MOD);
                }
                if (eval_poly((int)ans) == 0) {
                    finish(_ok, "Correct root found: %lld", ans);
                } else {
                    finish(_wa, "Value %lld is not a root (f(x) != 0)", ans);
                }
            }
        }
        else {

            long long x;
            bool is_valid_num = true;
            try {
                size_t idx;
                x = stoll(token, &idx);
                if (idx != token.size()) is_valid_num = false;
            } catch (...) {
                is_valid_num = false;
            }

            if (is_valid_num) {

                if (x < 0 || x >= MOD) {
                    cout << -1 << endl;
                    finish(_pe, "Query x=%lld out of range [0, %d)", x, MOD);
                }
                queries++;
                if (queries % 10 == 0) log_metrics();
                long long val = eval_poly((int)x);
                cout << val << endl;
            } else {
                finish(_pe, "Invalid token '%s'", token.c_str());
            }
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000003;
const int QUERY_LIMIT_VAL = 50;

long long queries = 0;
long long query_limit = QUERY_LIMIT_VAL;

vector<int> poly;

void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {

    }
}

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

long long eval_poly(const vector<int>& a, long long x) {
    long long res = 0;

    x %= MOD;
    if (x < 0) x += MOD;

    for (int i = (int)a.size() - 1; i >= 0; --i) {
        res = (res * x + a[i]) % MOD;
    }
    return res;
}

bool has_root(const vector<int>& a) {
    for (int x = 0; x < MOD; ++x) {
        if (eval_poly(a, x) == 0) return true;
    }
    return false;
}

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int k = inf.readInt();

    inf.skipBlanks();
    if (!inf.eof()) {

        for (int i = 0; i <= k; ++i) {
            poly.push_back(inf.readInt());
        }
    } else {

        while (true) {
            poly.assign(k + 1, 0);
            bool all_zero = true;
            for (int i = 0; i <= k; ++i) {
                poly[i] = rnd.next(MOD);
                if (poly[i] > 0) all_zero = false;
            }
            if (!all_zero) break;
        }
    }

    log_metrics();

    while (true) {
        string type;

        if (!(cin >> type)) {

            finish(_pe, "Unexpected EOF reading query type");
        }

        if (type == "?") {
            long long x;
            if (!(cin >> x)) finish(_pe, "Expected integer after '?'");

            if (x < 0 || x >= MOD) {
                cout << -1 << endl;
                finish(_pe, format("Query x=%lld out of range [0, %d)", x, MOD));
            }

            queries++;

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

            if (queries > 200) {
                finish(_pe, "Hard query limit exceeded (>200)");
            }

            long long val = eval_poly(poly, x);
            cout << val << endl;

        } else if (type == "!") {
            long long x;
            if (!(cin >> x)) finish(_pe, "Expected integer after '!'");

            if (x == -1) {

                if (has_root(poly)) {
                    finish(_wa, "Contestant claims no root, but a root exists");
                } else {
                    finish(_ok, "Correct (no root)");
                }
            } else {

                long long val = eval_poly(poly, x);
                if (val == 0) {
                    finish(_ok, "Correct (root found)");
                } else {
                    finish(_wa, format("Output %lld is not a root (f(x) = %lld)", x, val));
                }
            }

            break;
        } else {
            finish(_pe, "Invalid query type: \"" + type + "\"");
        }
    }

    return 0;
}

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000003;

long long eval_poly(const vector<int>& a, int x) {
    long long res = 0;
    for (int i = (int)a.size() - 1; i >= 0; --i) {
        res = (res * x + a[i]) % MOD;
    }
    return res;
}

bool has_root(const vector<int>& a) {
    for (int x = 0; x < MOD; ++x) {
        if (eval_poly(a, x) == 0) return true;
    }
    return false;
}

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

    string mode = opt<string>("mode", "non");
    int k_arg = opt<int>("k", -1);

    int k;
    if (k_arg != -1) {
        k = k_arg;
    } else {

        int r = rnd.next(100);
        if (r < 5) k = 0;
        else if (r < 20) k = rnd.next(1, 5);
        else k = rnd.next(6, 10);
    }

    int type = rnd.next(3);

    long long seed = atoll(argv[1]);
    if (seed == 1) { k = 10; type = 1; }
    else if (seed == 2) { k = 10; type = 2; }
    else if (seed == 3) { k = 0; type = 2; }
    else if (seed == 4) { k = 1; type = 1; }
    else if (seed == 5) { k = 5; type = 0; }

    if (k == 0) type = 2;

    if (mode == "adp") {
        cout << k << endl;
        return 0;
    }

    vector<int> a(k + 1);
    int retry_count = 0;
    const int MAX_RETRIES = 10;
    while (true) {

        for (int i = 0; i <= k; ++i) {
            a[i] = rnd.next(MOD);
        }

        bool all_zero = true;
        for (int x : a) if (x > 0) all_zero = false;
        if (all_zero) {

            a[rnd.next(k + 1)] = rnd.next(1, MOD - 1);
        }

        if (type == 1) {

            int x0 = rnd.next(MOD);

            long long val = 0;
            long long p = x0;
            for (int i = 1; i <= k; ++i) {
                val = (val + (long long)a[i] * p) % MOD;
                p = (p * x0) % MOD;
            }

            a[0] = (MOD - val) % MOD;

            bool az = true;
            for (int x : a) if (x > 0) az = false;
            if (az) continue;

            break;

        } else if (type == 2) {

            retry_count++;
            if (retry_count > MAX_RETRIES || !has_root(a)) break;
        } else {

            break;
        }
    }

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

    return 0;
}