This is the hard version of the problem. The difference between the versions is that in this version, the sum of the lengths of the articles over all queries must not exceed $2.5\cdot 10^4$.

This is an interactive problem.

The RiOI Team has recently developed a text editor named RiOI Editor. The editor works with exactly one integer parameter $W$ — the width of each line. It is known that $1 \leq W \leq 10^5$.

As you cannot understand the RiOI Language, from your point of view, words differ from each other only by their length. Hence, an article of length $n$ is defined as a sequence $a$ consisting of $n$ positive integers, where $a_i$ is the length of the $i$-th word in the article. The RiOI Editor displays the article $[a_1, a_2,\ldots, a_n]$ on screen as follows:

* If $\max(a_1, a_2, \ldots, a_n) > W$, the editor is unable to display the article;
* Otherwise, the editor is able to display the article by the following process:
  + Initially, $l = 1$, and $s = 0$. During the whole process, $l$ always denotes the current number of lines in the editor, and $s$ always denotes the sum of lengths of words in the last line;
  + Then, for each $1\le i\le n$:
    - If $s + a_i \leq W$, the word is inserted at the end of the current line. Thus, $l$ remains unchanged, and $s$ gets increased by $a_i$.
    - Otherwise, the word is inserted into a new line. Thus, $l$ becomes $l + 1$, and $s$ becomes $a_i$.
  + The number of lines needed to display the article is the final value of $l$.

You are very interested in the editor, so you decide to find out the value of $W$ by inputting some articles into the editor and observing the number of lines needed to display each article.

Formally, you can query the jury at most $2$ times. In each query, you input an article $[a_1, a_2, \ldots, a_n]$ ($1\leq n \leq 10^5$) to the editor, and the jury will respond to you with:

* The number of lines needed to display the article, if the editor is able to display it;
* $0$, if the editor is unable to display the article.

Additional constraint in this version: the sum of the lengths of the articles (i.e., $n$) over all queries must not exceed $2.5\cdot 10^4$.

Input

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

Interaction

For each test case, you can make up to $2$ queries to find out the value of $W$. It is guaranteed that $1\leq W\leq 10^5$.

To make a query, you should print a new line in the following format:

* $\texttt{? } n\texttt{ }a_1\texttt{ }a_2\texttt{ }\ldots\texttt{ }a_n$ ($1 \leq n, a_i \leq 10^5$) — the article you input to the editor.

The sum of $n$ over all queries must not exceed $2.5\cdot 10^4$.

At the end of each query, the jury will print an integer, as described in the statements.

To report that you have found the value of $W$, print a new line in the following format:

* $\texttt{! } W$ — the parameter of the editor.

Printing the answer does not count as one of the $2$ queries.

After that, proceed to process the next test case or terminate the program if it was the last test case.

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 $-1$ 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.

The interactor in this problem is adaptive. It means that the value of $W$ may change during the interaction, but it is guaranteed that there is always at least one integer $W$ satisfying all the queries.

Example

Input

```
2

2

1

0
```

Output

```
? 5 1 9 4 6 1

? 2 10 10

! 20
? 1 2

! 1
```

Note

In the first test case:

* For the first query, the total length of the words is $1+9+4+6+1=21$, and the article is displayed in two lines, so $W<21$;
* For the second query, the total length of the words is $10+10=20$, and the article is displayed in one line, so $W\ge 20$.

Thus, we have determined $W = 20$.

In the second test case, the editor cannot display the article in the only query. Thus, $W < 2$, so it can only be $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 << "\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) {
    return (cin >> s) ? true : false;
}

static bool readLongLong(long long& x) {
    return (cin >> x) ? true : false;
}

static long long linesNeededIfDisplayable(const vector<int>& a, int W) {
    int mx = 0;
    for (int v : a) mx = max(mx, v);
    if (mx > W) return 0;

    long long l = 1;
    long long s = 0;
    for (int v : a) {
        if (s + v <= W) {
            s += v;
        } else {
            l++;
            s = v;
        }
    }
    return l;
}

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

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

    int t = 0;
    try {
        t = inf.readInt();
    } catch (...) {
        query_limit = 25000;
        log_metrics();
        finish(_fail, "Failed to read t from inf");
    }
    if (t < 1 || t > 10) {
        query_limit = 25000;
        log_metrics();
        finish(_fail, "Invalid t in inf");
    }

    vector<int> hiddenW(t);
    for (int i = 0; i < t; i++) {
        int w = 0;
        try {
            w = inf.readInt();
        } catch (...) {
            query_limit = 25000;
            log_metrics();
            finish(_fail, "Failed to read W from inf");
        }
        if (w < 1 || w > 100000) {
            query_limit = 25000;
            log_metrics();
            finish(_fail, "Invalid W in inf");
        }
        hiddenW[i] = w;
    }

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

    log_metrics();

    cout << t << "\n" << flush;

    for (int tc = 0; tc < t; tc++) {
        int W = hiddenW[tc];

        long long query_count = 0;
        long long sum_n_this_case = 0;

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

            if (cmd == "?") {
                long long nll = 0;
                if (!readLongLong(nll)) {
                    cout << -1 << "\n" << flush;
                    finish(_pe, "Malformed query: missing n");
                }
                if (nll < 1 || nll > 100000) {
                    cout << -1 << "\n" << flush;
                    finish(_wa, "Invalid query: n out of range");
                }
                int n = (int)nll;

                vector<int> a;
                a.reserve(n);
                for (int i = 0; i < n; i++) {
                    long long xll = 0;
                    if (!readLongLong(xll)) {
                        cout << -1 << "\n" << flush;
                        finish(_pe, "Malformed query: not enough a_i");
                    }
                    if (xll < 1 || xll > 100000) {
                        cout << -1 << "\n" << flush;
                        finish(_wa, "Invalid query: a_i out of range");
                    }
                    a.push_back((int)xll);
                }

                query_count++;
                sum_n_this_case += n;
                queries += n;

                if (queries > hard_cap) {
                    cout << -1 << "\n" << flush;
                    finish(_pe, "Hard cap exceeded (possible infinite loop/output spam)");
                }

                long long ans = linesNeededIfDisplayable(a, W);
                cout << ans << "\n" << flush;
            } else if (cmd == "!") {
                long long guess = 0;
                if (!readLongLong(guess)) {
                    cout << -1 << "\n" << flush;
                    finish(_pe, "Malformed answer: missing W");
                }
                if (guess < 1 || guess > 100000) {
                    cout << -1 << "\n" << flush;
                    finish(_wa, "Answer W out of range");
                }
                if ((int)guess != W) {
                    finish(_wa, "Wrong answer");
                }
                break;
            } else {
                cout << -1 << "\n" << flush;
                finish(_pe, "Unknown command (expected '?' or '!')");
            }
        }

        (void)query_count;
        (void)sum_n_this_case;
    }

    string extra;
    if (cin >> extra) {
        finish(_pe, "Extra output after finishing all test cases");
    }

    finish(_ok, "OK");
    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 string trim_copy(string s) {
    size_t i = 0;
    while (i < s.size() && isspace((unsigned char)s[i])) i++;
    size_t j = s.size();
    while (j > i && isspace((unsigned char)s[j - 1])) j--;
    return s.substr(i, j - i);
}

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

static bool read_ll(long long& x) {
    if (!(cin >> x)) return false;
    return true;
}

struct Feasible {
    int L = 1, R = 100000;
};

struct ReplyChoice {
    int reply = 0;
    int newL = 1, newR = 0;
    int size() const { return (newL <= newR) ? (newR - newL + 1) : 0; }
};

static int compute_lines_greedy(const vector<int>& a, int W) {
    int l = 1;
    int s = 0;
    for (int x : a) {
        if (s + x <= W) {
            s += x;
        } else {
            l++;
            s = x;
        }
    }
    return l;
}

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

    int t = 0;
    try {
        t = inf.readInt(1, 10, "t");
    } catch (...) {
        finish(_pe, "failed to read t from inf");
    }

    query_limit = 2LL * t;
    log_metrics();

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

    auto read_nonempty_line_from_inf = [&]() -> string {
        while (true) {
            if (inf.seekEof()) return string();
            string line;
            try {
                line = inf.readLine();
            } catch (...) {
                return string();
            }
            line = trim_copy(line);
            if (!line.empty()) return line;
        }
    };

    long long total_n_over_all_queries = 0;
    const long long sum_n_limit = 25000;
    const long long hard_cap = max(200000LL, 10LL * query_limit);

    for (int tc = 1; tc <= t; tc++) {
        string line = read_nonempty_line_from_inf();
        if (line.empty()) finish(_pe, "unexpected EOF while reading test case parameters");

        vector<long long> vals;
        {
            stringstream ss(line);
            long long x;
            while (ss >> x) vals.push_back(x);
        }
        if (vals.empty()) finish(_pe, "empty parameter line for test case");
        long long a0 = vals[0];
        long long a1 = (vals.size() >= 2 ? vals[1] : vals[0]);

        if (a0 < 1 || a0 > 100000 || a1 < 1 || a1 > 100000) finish(_pe, "inf parameters out of range");
        int L = (int)a0, R = (int)a1;
        if (L > R) swap(L, R);

        Feasible feasible{L, R};
        int queries_in_case = 0;

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

            if (tok == "?") {
                long long nll;
                if (!read_ll(nll)) finish(_pe, "missing n after '?'");
                if (nll < 1 || nll > 100000) finish(_pe, "n out of range");
                int n = (int)nll;

                queries++;
                queries_in_case++;
                total_n_over_all_queries += n;
                if (queries > hard_cap) finish(_pe, "too many queries (hard cap exceeded)");
                if (total_n_over_all_queries > sum_n_limit) finish(_pe, "sum of n over all queries exceeded 25000");
                log_metrics();

                vector<int> a(n);
                int maxa = 0;
                for (int i = 0; i < n; i++) {
                    long long xll;
                    if (!read_ll(xll)) finish(_pe, "not enough a_i values");
                    if (xll < 1 || xll > 100000) finish(_pe, "a_i out of range");
                    a[i] = (int)xll;
                    maxa = max(maxa, a[i]);
                }

                auto response_at = [&](int W, unordered_map<int,int>& memo) -> int {
                    if (W < maxa) return 0;
                    auto it = memo.find(W);
                    if (it != memo.end()) return it->second;
                    int v = compute_lines_greedy(a, W);
                    memo.emplace(W, v);
                    return v;
                };

                auto first_width_leq_lines = [&](int lo, int hi, int target, unordered_map<int,int>& memo) -> int {

                    if (lo > hi) return hi + 1;
                    if (response_at(hi, memo) > target) return hi + 1;
                    int l = lo, r = hi;
                    while (l < r) {
                        int m = l + (r - l) / 2;
                        if (response_at(m, memo) <= target) r = m;
                        else l = m + 1;
                    }
                    return l;
                };

                auto interval_for_reply = [&](int replyVal, unordered_map<int,int>& memo) -> ReplyChoice {
                    ReplyChoice rc;
                    rc.reply = replyVal;

                    int curL = feasible.L, curR = feasible.R;
                    if (replyVal == 0) {
                        int r = min(curR, maxa - 1);
                        rc.newL = curL;
                        rc.newR = r;
                        return rc;
                    }

                    if (curR < maxa) {
                        rc.newL = 1; rc.newR = 0;
                        return rc;
                    }
                    int lo0 = max(curL, maxa), hi0 = curR;

                    int lines_lo = response_at(lo0, memo);
                    int lines_hi = response_at(hi0, memo);
                    if (lines_lo < replyVal || lines_hi > replyVal) {
                        rc.newL = 1; rc.newR = 0;
                        return rc;
                    }

                    int left = first_width_leq_lines(lo0, hi0, replyVal, memo);
                    if (left == hi0 + 1) {
                        rc.newL = 1; rc.newR = 0;
                        return rc;
                    }

                    int right = hi0;
                    if (replyVal > 1) {
                        int t2 = first_width_leq_lines(lo0, hi0, replyVal - 1, memo);
                        if (t2 != hi0 + 1) right = t2 - 1;
                    }

                    rc.newL = max(lo0, left);
                    rc.newR = min(hi0, right);
                    return rc;
                };

                ReplyChoice best;
                best.reply = 0;
                best.newL = 1;
                best.newR = 0;

                unordered_map<int,int> memo;
                memo.reserve(512);

                const int range_len = feasible.R - feasible.L + 1;
                const int small_scan_threshold = 2000;
                bool used_exact = false;
                if (range_len <= small_scan_threshold) {
                    int curL = feasible.L, curR = feasible.R;
                    int bestLen = -1;
                    int bestReply = 0;
                    int bestSegL = curL, bestSegR = curL - 1;

                    int segL = curL;
                    int prev = response_at(curL, memo);
                    for (int w = curL + 1; w <= curR; w++) {
                        int cur = response_at(w, memo);
                        if (cur != prev) {
                            int segR = w - 1;
                            int len = segR - segL + 1;
                            if (len > bestLen ||
                                (len == bestLen && (segL < bestSegL ||
                                                    (segL == bestSegL && segR > bestSegR) ||
                                                    (segL == bestSegL && segR == bestSegR && prev < bestReply)))) {
                                bestLen = len;
                                bestReply = prev;
                                bestSegL = segL;
                                bestSegR = segR;
                            }
                            segL = w;
                            prev = cur;
                        }
                    }
                    {
                        int segR = curR;
                        int len = segR - segL + 1;
                        if (len > bestLen ||
                            (len == bestLen && (segL < bestSegL ||
                                                (segL == bestSegL && segR > bestSegR) ||
                                                (segL == bestSegL && segR == bestSegR && prev < bestReply)))) {
                            bestLen = len;
                            bestReply = prev;
                            bestSegL = segL;
                            bestSegR = segR;
                        }
                    }

                    best.reply = bestReply;
                    best.newL = bestSegL;
                    best.newR = bestSegR;
                    used_exact = true;
                }

                if (!used_exact) {

                    vector<int> widths;
                    widths.reserve(8);
                    int curL = feasible.L, curR = feasible.R;
                    auto addW = [&](int w) {
                        if (w < curL || w > curR) return;
                        widths.push_back(w);
                    };
                    addW(curL);
                    addW(curR);
                    addW(curL + (curR - curL) / 2);
                    addW(curL + (curR - curL) / 4);
                    addW(curL + (curR - curL) * 3 / 4);
                    addW(maxa);
                    addW(maxa - 1);

                    sort(widths.begin(), widths.end());
                    widths.erase(unique(widths.begin(), widths.end()), widths.end());

                    vector<int> candidateReplies;
                    candidateReplies.reserve(widths.size() + 1);

                    if (feasible.L <= maxa - 1 && feasible.R >= feasible.L) candidateReplies.push_back(0);

                    for (int w : widths) {
                        int r = response_at(w, memo);
                        candidateReplies.push_back(r);
                    }
                    sort(candidateReplies.begin(), candidateReplies.end());
                    candidateReplies.erase(unique(candidateReplies.begin(), candidateReplies.end()), candidateReplies.end());

                    auto better = [&](const ReplyChoice& A, const ReplyChoice& B) -> bool {

                        int asz = A.size(), bsz = B.size();
                        if (asz != bsz) return asz > bsz;
                        if (A.newL != B.newL) return A.newL < B.newL;
                        if (A.newR != B.newR) return A.newR > B.newR;
                        return A.reply < B.reply;
                    };

                    for (int r : candidateReplies) {
                        ReplyChoice rc = interval_for_reply(r, memo);
                        if (rc.size() <= 0) continue;
                        if (best.size() <= 0 || better(rc, best)) best = rc;
                    }

                    if (best.size() <= 0) {

                        int r = response_at(feasible.L, memo);
                        best = interval_for_reply(r, memo);
                        if (best.size() <= 0) finish(_pe, "internal: could not maintain non-empty feasible set");
                    }
                }

                feasible.L = best.newL;
                feasible.R = best.newR;

                cout << best.reply << "\n";
                cout.flush();
            } else if (tok == "!") {
                long long ansll;
                if (!read_ll(ansll)) finish(_pe, "missing W after '!'");
                if (ansll < 1 || ansll > 100000) finish(_pe, "reported W out of range");
                int ans = (int)ansll;

                if (ans < feasible.L || ans > feasible.R) {
                    finish(_wa, "answer not consistent with interaction");
                }
                if (feasible.L != feasible.R || feasible.L != ans) {
                    finish(_wa, "answer not uniquely determined by interaction");
                }
                break;
            } else {
                finish(_pe, "invalid command token (expected '?' or '!')");
            }
        }
    }

    string extra;
    if (cin >> extra) finish(_pe, "extra output after all test cases");

    finish(_ok, "OK");
    return 0;
}

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

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

static int pickStructuredW(long long seed, int minW, int maxW) {
    if (minW == maxW) return minW;

    if (seed == 1) return minW;
    if (seed == 2) return maxW;
    if (seed == 3) return min(maxW, minW + 1);

    int span = maxW - minW;

    int roll = rnd.next(1, 100);
    long long w = -1;

    if (roll <= 18) {
        w = (long long)minW + rnd.next(0, min(12, span));
    } else if (roll <= 36) {
        w = (long long)maxW - rnd.next(0, min(12, span));
    } else if (roll <= 68) {
        int mid = minW + (maxW - minW) / 2;
        int delta = rnd.next(-2500, 2500);
        w = (long long)mid + delta;
    } else if (roll <= 86) {
        vector<int> cand;
        for (int p = 0; p <= 17; p++) {
            int base = 1 << p;
            for (int d : {-2, -1, 0, 1, 2}) {
                long long v = (long long)base + d;
                if (v >= minW && v <= maxW) cand.push_back((int)v);
            }
        }
        for (int p = 0; p <= 17; p++) {
            int base = (1 << p) - 1;
            for (int d : {-2, -1, 0, 1, 2}) {
                long long v = (long long)base + d;
                if (v >= minW && v <= maxW) cand.push_back((int)v);
            }
        }
        if (!cand.empty()) {
            w = cand[rnd.next(0, (int)cand.size() - 1)];
        } else {
            w = rnd.next(minW, maxW);
        }
    } else {
        w = rnd.next(minW, maxW);
    }

    return clampInt(w, minW, maxW);
}

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

    string mode = opt<string>("mode", "non");
    int minW = opt<int>("minW", 1);
    int maxW = opt<int>("maxW", 100000);

    if (minW < 1) minW = 1;
    if (maxW > 100000) maxW = 100000;
    if (minW > maxW) swap(minW, maxW);

    long long seed = 1;
    if (argc >= 2) {
        seed = atoll(argv[1]);
        if (seed == 0) seed = 1;
    }

    cout << 1 << "\n";

    if (mode == "non") {
        int W = pickStructuredW(seed, minW, maxW);
        cout << W << "\n";
        return 0;
    }

    if (mode == "adp") {
        int L = minW, R = maxW;

        if (L == R) {

        } else if (seed == 1) {
            L = R = minW;
        } else if (seed == 2) {
            L = R = maxW;
        } else if (seed == 3) {
            L = minW;
            R = min(maxW, minW + 1);
        } else {

            L = minW;
            R = maxW;
        }

        cout << L << " " << R << "\n";
        return 0;
    }

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


### Problem Statement

This is an **interactive problem** (where your program and the judge program interact through Standard Input and Output).

There is a simple connected undirected graph with $N$ vertices and $M$ edges.
The vertices are numbered with integers from $1$ to $N$.

Initially, you are at vertex $1$.
Repeat moving to an adjacent vertex at most $2N$ times to reach vertex $N$.

Here, you do not initially know all edges of the graph, but you will be informed of the vertices adjacent to the vertex you are at.

### Constraints

* $2\leq N\leq100$
* $N-1\leq M\leq\dfrac{N(N-1)}2$
* The graph is simple and connected.
* All input values are integers.

### Input and Output

First, receive the number of vertices $N$ and the number of edges $M$ in the graph from Standard Input:

```
$N$ $M$
```

Next, you get to repeat the operation described in the problem statement at most $2N$ times against the judge.

At the beginning of each operation, the vertices adjacent to the vertex you are currently at are given from Standard Input in the following format:

```
$k$ $v _ 1$ $v _ 2$ $\ldots$ $v _ k$
```

Here, $v _ i\ (1\leq i\leq k)$ are integers between $1$ and $N$ such that $v _ 1\lt v _ 2\lt\cdots\lt v _ k$.

Choose one of $v _ i\ (1\leq i\leq k)$ and print it to Standard Output in the following format:

```
$v _ i$
```

After this operation, you will be at vertex $v _ i$.

If you perform more than $2N$ operations or print invalid output, the judge will send `-1` to Standard Input.

If the destination of a move is vertex $N$, the judge will send `OK` to Standard Input and terminate.

When receiving `-1` or `OK`, immediately terminate the program.

### Notes

* **In each output, insert a newline at the end and flush Standard Output. Otherwise, the verdict may be TLE.**
* **The verdict will be indeterminate if the program prints invalid output or quits prematurely in the middle of the interaction.**
* Terminate the program immediately after reaching vertex $N$. Otherwise, the verdict will be indeterminate.
* **The judge for this problem is adaptive. This means that the graph may change without contradicting the constraints or previous outputs.**

### Sample Interaction

In the following sample interaction, we have $N=4$, $M=5$, and the graph in the figure below.

![](https://img.atcoder.jp/abc305/ae6ce1b3c8e950777761893a567c4d11.png)

| Input | Output | Description |
| --- | --- | --- |
| `4 5` |  | $N$ and $M$ are given. |
| `2 2 3` |  | You start at vertex $1$. The vertices adjacent to vertex $1$ are given. |
|  | `3` | You choose to go to vertex $v _ 2=3$. |
|
| `3 1 2 4` |  | The vertices adjacent to vertex $3$ are given. |
|  | `2` | You choose to go to vertex $v _ 2=2$. |
|
| `3 1 3 4` |  | The vertices adjacent to vertex $2$ are given. |
|  | `4` | You choose to go to vertex $v _ 3=4$. |
|
| `OK` |  | Since you have reached vertex $4$ within $8(=2\times4)$ moves, `OK` is passed. |

You will be judged as correct if you immediately terminate the program after receiving `OK`.

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

using namespace std;

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

void log_metrics() {

    if (tout.is_open()) {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    }
}

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 N = inf.readInt();
    int M = inf.readInt();

    query_limit = 2LL * N;

    log_metrics();

    vector<vector<int>> adj(N + 1);
    for (int i = 0; i < M; i++) {
        int u = inf.readInt();
        int v = inf.readInt();
        if (u >= 1 && u <= N && v >= 1 && v <= N) {
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
    }

    for (int i = 1; i <= N; i++) {
        sort(adj[i].begin(), adj[i].end());
    }

    cout << N << " " << M << endl;

    int curr = 1;

    if (curr == N) {
        cout << "OK" << endl;
        finish(_ok, "Start is goal");
    }

    while (true) {

        if (queries >= query_limit) {
            cout << "-1" << endl;
            finish(_wa, "Move limit exceeded (" + to_string(query_limit) + ")");
        }

        const vector<int>& neighbors = adj[curr];
        cout << neighbors.size();
        for (int v : neighbors) {
            cout << " " << v;
        }
        cout << endl;

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

        int next_v = -1;
        try {
            size_t pos;
            next_v = stoi(token, &pos);

            if (pos != token.size()) {
                cout << "-1" << endl;
                finish(_wa, "Invalid output format: expected integer, got '" + token + "'");
            }
        } catch (...) {

            cout << "-1" << endl;
            finish(_wa, "Invalid output format: expected integer, got '" + token + "'");
        }

        bool valid_move = false;
        for (int v : neighbors) {
            if (v == next_v) {
                valid_move = true;
                break;
            }
        }

        if (!valid_move) {
            cout << "-1" << endl;
            finish(_wa, "Invalid move: vertex " + to_string(next_v) + " is not adjacent to " + to_string(curr));
        }

        curr = next_v;
        queries++;

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

        if (curr == N) {
            cout << "OK" << endl;
            finish(_ok, "Reached goal vertex N");
        }
    }

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

    if (query_limit > 0) {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    }
}

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

vector<vector<int>> adj;

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int N = inf.readInt();
    int M = inf.readInt();

    query_limit = 2LL * N;

    bool is_adaptive = inf.seekEof();

    adj.assign(N + 1, vector<int>());

    if (!is_adaptive) {

        for (int i = 0; i < M; ++i) {
            int u = inf.readInt();
            int v = inf.readInt();

            if (u < 1 || u > N || v < 1 || v > N) {
                finish(_fail, "Invalid vertex index in static input");
            }
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
    } else {

        rnd.setSeed(N * 72341LL + M * 91238LL + 42LL);

        vector<int> nodes(N);
        iota(nodes.begin(), nodes.end(), 1);
        shuffle(nodes.begin(), nodes.end());

        set<pair<int, int>> edges;
        auto add_edge_internal = [&](int u, int v) {
            if (u > v) swap(u, v);
            if (u == v) return false;
            if (edges.count({u, v})) return false;
            edges.insert({u, v});
            adj[u].push_back(v);
            adj[v].push_back(u);
            return true;
        };

        for (int i = 1; i < N; ++i) {
            int parent = nodes[rnd.next(i)];
            add_edge_internal(nodes[i], parent);
        }

        long long current_m = N - 1;
        int fails = 0;

        while (current_m < M && fails < 2000) {
            int u = rnd.next(1, N);
            int v = rnd.next(1, N);
            if (add_edge_internal(u, v)) {
                current_m++;
                fails = 0;
            } else {
                fails++;
            }
        }

        if (current_m < M) {

            for (int i = 1; i <= N && current_m < M; ++i) {
                for (int j = i + 1; j <= N && current_m < M; ++j) {
                     if (add_edge_internal(i, j)) {
                         current_m++;
                     }
                }
            }
        }
    }

    cout << N << " " << M << endl;

    int curr = 1;

    while (true) {

        if (curr == N) {
            cout << "OK" << endl;
            finish(_ok, "Reached N");
        }

        if (queries >= query_limit) {
            cout << "-1" << endl;
            finish(_wa, "Too many moves");
        }

        vector<int>& neighbors = adj[curr];
        sort(neighbors.begin(), neighbors.end());

        cout << neighbors.size();
        for (int v : neighbors) {
            cout << " " << v;
        }
        cout << endl;

        int next_node;
        if (!(cin >> next_node)) {
            finish(_wa, "Contestant closed stream or invalid output format");
        }

        bool valid = false;
        for (int v : neighbors) {
            if (v == next_node) {
                valid = true;
                break;
            }
        }

        if (!valid) {

            cout << "-1" << endl;
            finish(_wa, "Invalid move: destination not adjacent");
        }

        curr = next_node;
        queries++;

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

    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_arg = opt<int>("N", -1);
    int m_arg = opt<int>("M", -1);

    long long seed_val = 0;
    try {
        if (argc > 1) seed_val = stoll(string(argv[1]));
    } catch (...) {}

    int N, M;
    bool manual_params = (n_arg != -1 || m_arg != -1);

    if (!manual_params && seed_val == 1) {
        N = 2; M = 1;
    } else if (!manual_params && seed_val == 2) {
        N = 100; M = 99;
    } else if (!manual_params && seed_val == 3) {
        N = 100; M = 100 * 99 / 2;
    } else {

        if (n_arg != -1) N = n_arg;
        else N = rnd.next(2, 100);

        long long min_m = N - 1;
        long long max_m = (long long)N * (N - 1) / 2;

        if (m_arg != -1) {
            M = m_arg;
            if (M < min_m) M = min_m;
            if (M > max_m) M = max_m;
        } else {

            int t = rnd.next(100);
            if (t < 50) {

                M = rnd.next((int)min_m, (int)min(max_m, min_m + 2 * N));
            } else if (t < 80) {

                M = rnd.next((int)max(min_m, max_m - 2 * N), (int)max_m);
            } else {

                M = rnd.next((int)min_m, (int)max_m);
            }
        }
    }

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

    set<pair<int, int>> edges_set;
    vector<pair<int, int>> edges;

    auto add_edge = [&](int u, int v) {
        if (u > v) swap(u, v);
        if (u != v && !edges_set.count({u, v})) {
            edges_set.insert({u, v});
            edges.push_back({u, v});
        }
    };

    int type = rnd.next(3);
    if (!manual_params && seed_val == 2) type = 0;
    if (!manual_params && seed_val == 3) type = 2;

    if (type == 0) {

        vector<int> path_nodes;
        path_nodes.push_back(0);
        if (N > 2) {
            vector<int> mids(N - 2);
            iota(mids.begin(), mids.end(), 1);
            shuffle(mids.begin(), mids.end());
            path_nodes.insert(path_nodes.end(), mids.begin(), mids.end());
        }
        if (N > 1) path_nodes.push_back(N - 1);

        for (size_t i = 0; i < path_nodes.size() - 1; ++i) {
            add_edge(path_nodes[i], path_nodes[i+1]);
        }
    } else if (type == 1) {

        vector<int> connected = {0};
        vector<int> remaining;
        for (int i = 1; i < N; ++i) remaining.push_back(i);
        shuffle(remaining.begin(), remaining.end());

        for (int u : remaining) {
            int v = connected[rnd.next(connected.size())];
            add_edge(u, v);
            connected.push_back(u);
        }
    } else {

        vector<int> nodes(N);
        iota(nodes.begin(), nodes.end(), 0);
        shuffle(nodes.begin(), nodes.end());
        for (int i = 1; i < N; ++i) {
            add_edge(nodes[i], nodes[rnd.next(i)]);
        }
    }

    int needed = M - (int)edges.size();
    long long total_pairs = (long long)N * (N - 1) / 2;

    if (needed > 0) {
        if (total_pairs - edges.size() < 2LL * needed) {

            vector<pair<int, int>> missing;
            for (int i = 0; i < N; ++i) {
                for (int j = i + 1; j < N; ++j) {
                    if (!edges_set.count({i, j})) {
                        missing.push_back({i, j});
                    }
                }
            }
            shuffle(missing.begin(), missing.end());
            for (int i = 0; i < needed; ++i) {
                add_edge(missing[i].first, missing[i].second);
            }
        } else {

            while ((int)edges.size() < M) {
                int u = rnd.next(0, N - 1);
                int v = rnd.next(0, N - 1);
                add_edge(u, v);
            }
        }
    }

    vector<int> label(N);
    label[0] = 1;
    label[N - 1] = N;
    if (N > 2) {
        vector<int> p;
        for (int i = 2; i <= N - 1; ++i) p.push_back(i);
        shuffle(p.begin(), p.end());
        int idx = 0;
        for (int i = 1; i < N - 1; ++i) label[i] = p[idx++];
    }

    cout << N << " " << M << endl;
    for (const auto& e : edges) {
        cout << label[e.first] << " " << label[e.second] << endl;
    }

    return 0;
}


You are standing at the very center of a field, which is divided into a grid of cells running north-south and east-west. A great treasure is hidden somewhere within one of these cells.

John Belzoni, a descendant of the famous treasure hunter Giovanni Battista Belzoni, actually discovered that treasure. Unfortunately enough, he died of heatstroke before successfully digging it out; he seems to have spent too long time wandering around the field.

John started his exploration from the central cell of the field where you stand now. All of his footprints leading to the treasure are left on the field, but you cannot identify the footprint on a cell until you reach there. The footprint on a cell indicates which of the four adjacent grid cells he proceeded to. It is known that John did not visit the same grid cell twice or more. You see a footprint on the central cell indicating that John’s first step was northward.

There is exactly one treasure cell in the field, and you will recognize it only when you are on it.

A possible situation of the field is shown in Figure G.1. John’s footprints are depicted as arrows in the cells. The treasure cell is depicted as ${ \bf \epsilon } ^ { \bullet } ( { \bf \vec { \tau } } _ { G } ^ { \bullet }$ . The shaded cell is where you initially stand.

![](images/4b0d167fa585b05654e0a3ebef224e7744cae45171f65111f2408ccac00e544b.jpg)
Figure G.1. Possible situation

Your task is to find the treasure in a limited number of steps. In a single step, you decide to take one of the four directions north, west, south, or east, and proceed to the adjacent cell in that direction. When you move on to the cell, you may find either the treasure, John’s footprint, or nothing. You do not have to follow John’s footprints. Unlike John’s route, you may visit the same cell more than once. John’s footprints will remain the same regardless of your exploration.

# Interaction

The interaction begins by receiving an integer $n$ $1 \leq n \leq 2 0 0 0 )$ ) from the standard input, followed by a newline. The integer $n$ means that the field is partitioned into $( 2 n + 1 ) \times ( 2 n + 1 )$ grid cells. You are initially on the cell $( n + 1 )$ -th from the west end and $( n + 1 )$ -th from the north end. After receiving the integer $n$ , you can start your exploration steps.

In each step, you send a single character meaning the direction of the cell to move to: ‘ˆ’ (caret) for north, $\cdot _ { < } ,$ (less than symbol) for west, ‘v’ (lowercase V) for south, and $\bullet _ { > } ,$ (greater than symbol) for east. The character should be sent to the standard output followed by a newline.

In its response, you will receive a character indicating what you find on the cell you moved to, followed by a newline. The character ‘G’ means that the treasure is there. The characters ‘ $\because \mathrm { ~  ~ \cdot ~ } < , \mathrm { ~  ~ \cdot ~ } _ { \mathrm { { V } } } ,$ , and $^ \bullet > ^ { : }$ ’ mean John’s footprint directing north, west, south, and east, respectively. The character ‘.’ (dot) means neither the treasure nor a footprint is on the cell.

When you find the treasure, that is, when you have received the character $\mathbf { \epsilon } ^ { \bullet } ( \mathbf { \vec { \jmath } } _ { G } ^ { \ \ \bullet }$ , the interaction stops and your program should terminate. You must reach the treasure cell within 30000 steps. Although following John’s steps will surely lead you to the treasure, that may require more than 30000 steps.

In any of the following cases, your submission will be judged as a wrong answer.

• The output format of your program is invalid.
• You specify a direction to move out of the grid.
• Extra outputs are made after reaching the treasure cell.
• You could not reach the treasure cell within 30000 steps.

The arrangement of the field (the place of the treasure cell and John’s footprints) is fixed before the interaction starts; it does not change during the interaction.

As some environments require flushing the output buffers, make sure that your outputs are actually sent. Otherwise, your outputs will never reach the judge. You are provided with a command-line tool for local testing. For more details, refer to the clarification in the contest system.

![](images/070e0d349e65cf8f76a10a085cf628e77c1f2b42ad7ee4f1f42ad2137bc62696.jpg)

In this interaction, the situation of the field in Figure G.1 is assumed.

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

static long long queries = 0;
static long long query_limit = 30000;
static const long long HARD_CAP = 100000;

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 n = inf.readInt();
    string path = inf.readToken();

    int side = 2 * n + 1;

    vector<string> grid(side, string(side, '.'));

    int r = n;
    int c = n;

    for (char move : path) {

        grid[r][c] = move;

        if (move == '^') r--;
        else if (move == 'v') r++;
        else if (move == '<') c--;
        else if (move == '>') c++;
        else {
            finish(_fail, "Invalid character in hidden input path");
        }

        if (r < 0 || r >= side || c < 0 || c >= side) {
            finish(_fail, "Hidden path goes out of bounds");
        }
    }

    grid[r][c] = 'G';

    log_metrics();

    cout << n << endl;

    int cur_r = n;
    int cur_c = n;

    while (true) {

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

        string token;
        cin >> token;

        if (cin.fail()) {
            finish(_wa, "Unexpected EOF (expected move direction)");
        }

        if (token.size() != 1) {
            finish(_wa, "Invalid input format: expected single character");
        }

        char move = token[0];
        int dr = 0, dc = 0;

        if (move == '^') dr = -1;
        else if (move == 'v') dr = 1;
        else if (move == '<') dc = -1;
        else if (move == '>') dc = 1;
        else {
            finish(_wa, "Invalid direction character");
        }

        cur_r += dr;
        cur_c += dc;
        queries++;

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

        if (cur_r < 0 || cur_r >= side || cur_c < 0 || cur_c >= side) {
            finish(_wa, "Move out of grid bounds");
        }

        char content = grid[cur_r][cur_c];

        cout << content << endl;

        if (content == 'G') {
            finish(_ok, "Treasure found");
        }
    }

    return 0;
}

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

int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
char dchar[] = {'^', '>', 'v', '<'};

string generate_spiral(int n, int mirror) {
    vector<int> cycle;
    if (mirror == 0) cycle = {0, 1, 2, 3};
    else cycle = {0, 3, 2, 1};

    int r = n, c = n;
    string path = "";

    int dir_idx = 0;

    int max_len = 200000;

    bool done = false;
    for (int len_idx = 0; ; ++len_idx) {
        int current_len = (len_idx / 2) + 1;
        int d = cycle[dir_idx];
        dir_idx = (dir_idx + 1) % 4;

        for (int k = 0; k < current_len; ++k) {
            int nr = r + dr[d];
            int nc = c + dc[d];

            if (nr < 0 || nr > 2 * n || nc < 0 || nc > 2 * n) {
                done = true;
                break;
            }

            path += dchar[d];
            r = nr;
            c = nc;

            if ((int)path.size() >= max_len) {
                done = true;
                break;
            }
        }
        if (done) break;
    }
    return path;
}

string generate_random_snake(int n) {
    set<pair<int,int>> visited;
    int r = n, c = n;
    visited.insert({r, c});
    string path = "";

    r = r - 1;
    path += '^';
    visited.insert({r, c});

    int max_len = 50000;

    while ((int)path.size() < max_len) {
        vector<int> cands;
        for(int i=0; i<4; ++i) {
            int nr = r + dr[i];
            int nc = c + dc[i];

            if (nr >= 0 && nr <= 2*n && nc >= 0 && nc <= 2*n) {

                if (visited.find({nr, nc}) == visited.end()) {
                    cands.push_back(i);
                }
            }
        }

        if (cands.empty()) break;

        int d = cands[rnd.next((int)cands.size())];
        r += dr[d];
        c += dc[d];
        visited.insert({r, c});
        path += dchar[d];
    }
    return path;
}

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

    string mode = opt<string>("mode", "non");

    if (mode == "adp") {

        int n;

        if (rnd.next(10) == 0) n = rnd.next(1, 50);
        else n = rnd.next(50, 2000);

        cout << n << endl;
        cout << rnd.next(2000000000) << endl;
    } else {

        int n;
        int type = rnd.next(100);
        if (type < 5) n = rnd.next(1, 10);
        else if (type < 20) n = rnd.next(11, 100);
        else if (type < 50) n = rnd.next(101, 500);
        else n = rnd.next(501, 2000);

        string path;

        if (rnd.next(3) == 0) {
            path = generate_random_snake(n);
        } else {
            path = generate_spiral(n, rnd.next(2));
        }

        if (path.empty()) path = "^";

        cout << n << endl;
        cout << path << endl;
    }

    return 0;
}


This is the easy version of the problem. In this version, you can send at most $\mathbf{7}$ commands.

This is an interactive problem.

Welcome, Duelists! In this interactive challenge, there is an unknown integer $x$ ($1 \le x \le 10^9$). You must make it equal to a given integer in the input $n$. By harnessing the power of "Mathmech" monsters, you can send a command to do one of the following:

|  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- |
| Command | Constraint | Result | Case | Update | Jury's response |
| "add $y$" | $-10^{18} \le y \le 10^{18}$ | $\mathrm{res} = x + y$ | $\text{if } 1 \le \mathrm{res} \le 10^{18}$ | $x \leftarrow \mathrm{res}$ | "1" |
| $\mathrm{else}$ | $x \leftarrow x$ | "0" |
| "mul $y$" | $1 \le y \le 10^{18}$ | $\mathrm{res} = x \cdot y$ | $\text{if } 1 \le \mathrm{res} \le 10^{18}$ | $x \leftarrow \mathrm{res}$ | "1" |
| $\mathrm{else}$ | $x \leftarrow x$ | "0" |
| "div $y$" | $1 \le y \le 10^{18}$ | $\mathrm{res} = x/y$ | $\text{if } y$ divides $x$ | $x \leftarrow \mathrm{res}$ | "1" |
| $\mathrm{else}$ | $x \leftarrow x$ | "0" |
| "digit" | — | $\mathrm{res} = S(x)$$^{\text{∗}}$ | — | $x \leftarrow \mathrm{res}$ | "1" |

You have to make $x$ equal to $n$ using at most $\mathbf{7}$ commands.

$^{\text{∗}}$$S(n)$ is a function that returns the sum of all the individual digits of a non-negative integer $n$. For example, $S(123) = 1 + 2 + 3 = 6$

Input

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

The first and only line of each test case contains one integer $n$ ($1 \le n \le 10^9$).

Interaction

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

To send a command, output a line in the following format:

* "add $y$" Add some integer $y$ ($-10^{18} \le y \le 10^{18}$) to $x$.

  The jury will output "1" if $x + y$ is within $[1, 10^{18}]$ (successful), and "0" otherwise. If successful, update $x \leftarrow x + y$.
* "mul $y$" Multiply $x$ by a positive integer $y$ ($1 \le y \le 10^{18}$).

  The jury will output "1" if $x \cdot y$ is within $[1, 10^{18}]$ (successful), and "0" otherwise. If successful, update $x \leftarrow x \cdot y$.
* "div $y$" Divide $x$ by a positive integer $y$ ($1 \le y \le 10^{18}$).

  The jury will output "1" if $y$ is a divisor of $x$ (successful), and "0" otherwise. If successful, update $x \leftarrow \frac{x}{y}$.
* "digit" Make $x$ equal to the sum of its digits.

  The jury will always output "1" and update $x \leftarrow S(x)$.

Note that commands are case sensitive.

When you have determined that $x$ is equal to $n$, output a line in the following format:

* "!" — where the jury will output a "1" if $n$ is equal to $x$, and "-1" otherwise.

Note that answering does not count toward your limit of $\mathbf{7}$ commands.

If your program makes more than $\mathbf{7}$ commands for one test case, or makes an invalid command, then the response to the command will be "-1". After receiving such a response, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, it may receive any other verdict.

After printing a command, do not forget to output the end of the 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;
* sys.stdout.flush() in Python;
* std::io::stdout().flush() in Rust;
* see the documentation for other languages.

The interactor is non-adaptive. The unknown integer $x$ does not change during the interaction.

Example

Input

```
2
100

0

1

1

1

5

1

1

1
```

Output

```
add -10

add 1

mul 10

!

digit

div 2

!
```

Note

|  |  |  |
| --- | --- | --- |
| Solution | Jury | Explanation |
|  | $\texttt{2}$ | There are 2 test cases. |
|  | $\texttt{100}$ | In the first test case, the unknown integer $x = 9$ and we have to make it equal to $n = 100$. |
| $\texttt{add -10}$ | $\texttt{0}$ | The answer to "add -10" is "0". This means that the addition command was not successful as $x + y = 9 + (-10) \le 0$, and $x$ remains $9$ after the command |
| $\texttt{add 1}$ | $\texttt{1}$ | The answer to "add 1" is "1". This means that the addition command was successful as $x + y = 9 + 1 = 10$, and $x$ changes to $10$ after the command. |
| $\texttt{mul 10}$ | $\texttt{1}$ | The answer to "mul 10" is "1". This means that the multiplication command was successful as $x \cdot y = 10 \cdot 10 = 100$, and $x$ changes to $100$ after the command. |
| $\texttt{!}$ | $\texttt{1}$ | The answer to "!" is "1". This means you have determined that $x$ equals $n$. |
|  | $\texttt{5}$ | In the second test case, the unknown integer $x = 1234$ and we have to make it equal to $n = 5$. |
| $\texttt{digit}$ | $\texttt{1}$ | The answer to "digit" is "1". This means that $x$ turned into the sum of its digits $1 + 2 + 3 + 4 = 10$, and $x$ changes to $10$ after the command. |
| $\texttt{div 2}$ | $\texttt{1}$ | The answer to "div 2" is "1". This means that the division command was successful as $y = 2$ is a divisor of $x = 10$, and $x$ changes to $\frac{x}{y} = \frac{10}{2} = 5$ after the command. |
| $\texttt{!}$ | $\texttt{1}$ | The answer to "!" is "1". This means you have determined that $x$ equals $n$. |

Note that the empty lines in the example input and output are for the sake of clarity, and do not occur in the real interaction.

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

using namespace std;

long long max_queries_used = 0;

const int QUERY_LIMIT = 7;

void log_metrics() {
    try {
        tout << "queries=" << max_queries_used << 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 sum_digits(long long val) {
    long long s = 0;
    while (val > 0) {
        s += val % 10;
        val /= 10;
    }
    return s;
}

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

    registerInteraction(argc, argv);

    atexit(log_metrics);

    int t = inf.readInt();

    cout << t << endl;

    log_metrics();

    for (int i = 0; i < t; i++) {
        long long n = inf.readLong();
        long long x = inf.readLong();

        cout << n << endl;

        int current_queries = 0;
        bool case_active = true;

        while (case_active) {
            string token;

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

            if (token == "?") {
                if (!(cin >> token)) {
                    finish(_wa, "Unexpected EOF reading command after '?'");
                }
            }

            if (token == "!") {

                if (x == n) {
                    cout << "1" << endl;
                    case_active = false;
                } else {
                    cout << "-1" << endl;
                    finish(_wa, format("Wrong guess: x (%lld) != n (%lld)", x, n));
                }
                continue;
            }

            current_queries++;

            if (current_queries > max_queries_used) {
                max_queries_used = current_queries;

                log_metrics();
            }

            if (current_queries > QUERY_LIMIT) {
                cout << "-1" << endl;
                finish(_wa, "Query limit exceeded (> 7)");
            }

            bool success = false;
            bool error = false;

            if (token == "add") {
                long long y;
                if (!(cin >> y)) error = true;
                else {

                    if (y < -1000000000000000000LL || y > 1000000000000000000LL) {
                        error = true;
                    } else {

                        long long res = x + y;
                        if (res >= 1 && res <= 1000000000000000000LL) {
                            x = res;
                            success = true;
                        }
                    }
                }
            }
            else if (token == "mul") {
                long long y;
                if (!(cin >> y)) error = true;
                else {

                    if (y < 1 || y > 1000000000000000000LL) {
                        error = true;
                    } else {

                        __int128 res = (__int128)x * y;
                        if (res >= 1 && res <= 1000000000000000000LL) {
                            x = (long long)res;
                            success = true;
                        }
                    }
                }
            }
            else if (token == "div") {
                long long y;
                if (!(cin >> y)) error = true;
                else {

                    if (y < 1 || y > 1000000000000000000LL) {
                        error = true;
                    } else {

                        if (x % y == 0) {
                            x /= y;
                            success = true;
                        }
                    }
                }
            }
            else if (token == "digit") {

                x = sum_digits(x);
                success = true;
            }
            else {

                error = true;
            }

            if (error) {
                cout << "-1" << endl;

                finish(_wa, "Invalid command or argument: " + token);
            } else {
                cout << (success ? "1" : "0") << endl;
            }
        }
    }

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

#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", 100);

    long long seed_val = 0;
    if (argc > 1) {
        try {
            seed_val = stoll(string(argv[1]));
        } catch (...) {
            seed_val = 0;
        }
    }

    struct Case {
        long long n, x;
    };
    vector<Case> cases;

    auto add = [&](long long n, long long x) {
        cases.push_back({n, x});
    };

    if (seed_val == 1) {

        add(1, 1);
        add(1000000000, 1000000000);
        add(1, 1000000000);
        add(1000000000, 1);
        add(500, 500);
        add(12345, 12345);
    } else if (seed_val == 2) {

        add(1, 999999999);
        add(100, 999999999);
        add(1000000000, 999999999);
        add(999999999, 1);
        add(10, 199999999);
    } else if (seed_val == 3) {

        add(100, 10);
        add(10, 100);
        add(1024, 2);
        add(2, 1024);
        for(long long p = 10; p <= 1000000000; p *= 10) {
            add(p, 1);
            add(1, p);
        }
    }

    if ((int)cases.size() > t) {
        shuffle(cases.begin(), cases.end());
        cases.resize(t);
    }

    while ((int)cases.size() < t) {
        int type = rnd.next(1, 6);
        long long n = 1, x = 1;

        if (type == 1) {
            n = rnd.next(1LL, 1000000000LL);
            x = rnd.next(1LL, 1000000000LL);
        } else if (type == 2) {
            n = rnd.next(1LL, 1000LL);
            x = rnd.next(1LL, 1000000000LL);
        } else if (type == 3) {
            n = rnd.next(1LL, 1000000000LL);
            x = rnd.next(1LL, 1000LL);
        } else if (type == 4) {
            n = rnd.next(1LL, 1000000000LL);
            long long delta = rnd.next(-5000LL, 5000LL);
            x = n + delta;
            if (x < 1) x = 1;
            if (x > 1000000000LL) x = 1000000000LL;
        } else if (type == 5) {
            n = rnd.next(1LL, 1000000000LL);
            int len = rnd.next(1, 9);
            x = 0;
            for(int k=0; k<len; ++k) x = x * 10 + 9;
            if (x < 1) x = 1;
        } else {
            long long base = rnd.next(1LL, 10000LL);
            long long k = rnd.next(1LL, 10000LL);
            if (rnd.next(0, 1)) {
                n = base;
                x = min(1000000000LL, base * k);
            } else {
                x = base;
                n = min(1000000000LL, base * k);
            }
        }
        add(n, x);
    }

    shuffle(cases.begin(), cases.end());

    println(t);
    for (const auto& c : cases) {
        if (mode == "adp") {

            println(c.n);
        } else {

            println(c.n, c.x);
        }
    }

    return 0;
}


This is an interactive problem.

Omkar has just come across a duck! The duck is walking on a grid with $n$ rows and $n$ columns ($2 \leq n \leq 25$) so that the grid contains a total of $n^2$ cells. Let's denote by $(x, y)$ the cell in the $x$-th row from the top and the $y$-th column from the left. Right now, the duck is at the cell $(1, 1)$ (the cell in the top left corner) and would like to reach the cell $(n, n)$ (the cell in the bottom right corner) by moving either down $1$ cell or to the right $1$ cell each second.

Since Omkar thinks ducks are fun, he wants to play a game with you based on the movement of the duck. First, for each cell $(x, y)$ in the grid, you will tell Omkar a nonnegative integer $a_{x,y}$ not exceeding $10^{16}$, and Omkar will then put $a_{x,y}$ uninteresting problems in the cell $(x, y)$. After that, the duck will start their journey from $(1, 1)$ to $(n, n)$. For each cell $(x, y)$ that the duck crosses during their journey (including the cells $(1, 1)$ and $(n, n)$), the duck will eat the $a_{x,y}$ uninteresting problems in that cell. Once the duck has completed their journey, Omkar will measure their mass to determine the total number $k$ of uninteresting problems that the duck ate on their journey, and then tell you $k$.

Your challenge, given $k$, is to exactly reproduce the duck's path, i. e. to tell Omkar precisely which cells the duck crossed on their journey. To be sure of your mastery of this game, Omkar will have the duck complete $q$ different journeys ($1 \leq q \leq 10^3$). Note that all journeys are independent: at the beginning of each journey, the cell $(x, y)$ will still contain $a_{x,y}$ uninteresting tasks.

Interaction

The interaction will begin with a line containing a single integer $n$ ($2 \leq n \leq 25$), the amount of rows and columns in the grid. Read it.

Your program should then print $n$ lines. The $x$-th line should contain $n$ integers $a_{x,1}, a_{x,2}, \dotsc, a_{x,n}$ satisfying $0 \leq a_{x,y} \leq 10^{16}$, where $a_{x,y}$ is the amount of uninteresting problems Omkar should place in the cell $(x, y)$.

After that, you will first receive a single integer $q$, the amount of journeys that the duck will take. $q$ queries will follow; each query will consist of a single line containing an integer $k$, the amount of uninteresting problems that the duck ate on that journey. After each query, given that you have determined that the duck visited the cells $(x_1, y_1), (x_2, y_2), \dotsc, (x_{2n - 1}, y_{2n - 1})$ in that order (it should always be true that $(x_1, y_1) = (1, 1)$ and $(x_{2n - 1}, y_{2n - 1}) = (n, n)$), you should output $2n - 1$ lines so that the $j$-th line contains the two integers $x_j, y_j$.

Bear in mind that if the sum on your path is $k$, but your path is different from the actual hidden path, then your solution is still wrong!

After printing each line 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

```
4

3
23

26

27
```

Output

```
1 2 3 6
4 6 2 10
9 0 7 3
2 8 8 2

1 1
1 2
1 3
2 3
2 4
3 4
4 4

1 1
2 1
3 1
3 2
3 3
3 4
4 4

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

Note

The duck's three journeys are illustrated below.

$1 + 2 + 3 + 2 + 10 + 3 + 2 = 23$

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

$1 + 4 + 9 + 0 + 7 + 3 + 2 = 26$

 ![](https://espresso.codeforces.com/51a62c32428b2281b9792c5262ea1a32cf485943.png)

$1 + 2 + 3 + 6 + 10 + 3 + 2 = 27$

 ![](https://espresso.codeforces.com/886765d811ec84faf5ba21a905186a032de79b63.png)

#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 parseInt128Bounded(const string& s, __int128& val) {
    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;
    }
    __int128 x = 0;
    for (; i < (int)s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        x = x * 10 + (c - '0');

    }
    val = neg ? -x : x;
    return true;
}

static bool parseLongLongInRange(const string& s, long long& out, long long lo, long long hi) {
    __int128 v;
    if (!parseInt128Bounded(s, v)) return false;
    if (v < (__int128)lo || v > (__int128)hi) return false;
    out = (long long)v;
    return true;
}

static bool parseULLInRange(const string& s, unsigned long long& out, unsigned long long lo, unsigned long long hi) {
    __int128 v;
    if (!parseInt128Bounded(s, v)) return false;
    if (v < 0) return false;
    if (v < (__int128)lo || v > (__int128)hi) return false;
    out = (unsigned long long)v;
    return true;
}

static bool validatePath(const vector<pair<int,int>>& p, int n) {
    if ((int)p.size() != 2 * n - 1) return false;
    if (p.front() != make_pair(1, 1)) return false;
    if (p.back() != make_pair(n, n)) return false;
    for (auto [x, y] : p) {
        if (x < 1 || x > n || y < 1 || y > n) return false;
    }
    for (int i = 1; i < (int)p.size(); i++) {
        int dx = p[i].first - p[i - 1].first;
        int dy = p[i].second - p[i - 1].second;
        if (!((dx == 1 && dy == 0) || (dx == 0 && dy == 1))) return false;
    }
    return true;
}

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

    int n = inf.readInt(2, 25, "n");
    int q = inf.readInt(1, 1000, "q");

    vector<vector<pair<int,int>>> hiddenPaths;
    hiddenPaths.reserve(q);

    for (int i = 0; i < q; i++) {
        int L = inf.readInt(1, 1000000, "L");
        vector<pair<int,int>> p;
        p.reserve(L);
        for (int j = 0; j < L; j++) {
            int x = inf.readInt(1, n, "x");
            int y = inf.readInt(1, n, "y");
            p.push_back({x, y});
        }
        if (L != 2 * n - 1 || !validatePath(p, n)) {

            query_limit = q;
            log_metrics();
            quitf(_fail, "Invalid hidden path in input (case corrupted)");
        }
        hiddenPaths.push_back(std::move(p));
    }

    query_limit = q;
    log_metrics();

    cout << n << endl;

    const unsigned long long A_MAX = 10000000000000000ULL;
    vector<vector<unsigned long long>> a(n + 1, vector<unsigned long long>(n + 1, 0));

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            string tok;
            if (!readToken(tok)) finish(_pe, "Unexpected EOF while reading grid values");
            unsigned long long v;
            if (!parseULLInRange(tok, v, 0ULL, A_MAX)) finish(_pe, "Invalid grid value (not in [0,1e16])");
            a[i][j] = v;
        }
    }

    cout << q << endl;

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

    for (int qi = 0; qi < q; qi++) {
        __int128 sum = 0;
        for (auto [x, y] : hiddenPaths[qi]) sum += (__int128)a[x][y];

        long long k = (long long)sum;
        cout << k << endl;

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

        vector<pair<int,int>> ans;
        ans.reserve(2 * n - 1);
        for (int t = 0; t < 2 * n - 1; t++) {
            string sx, sy;
            if (!readToken(sx)) finish(_pe, "Unexpected EOF while reading answer path");
            if (!readToken(sy)) finish(_pe, "Unexpected EOF while reading answer path");
            long long x, y;
            if (!parseLongLongInRange(sx, x, 1, n) || !parseLongLongInRange(sy, y, 1, n))
                finish(_pe, "Invalid coordinates in answer path");
            ans.push_back({(int)x, (int)y});
        }

        if (!validatePath(ans, n)) finish(_pe, "Answer path is not a valid monotone path");

        if (ans != hiddenPaths[qi]) {
            finish(_wa, "Wrong path");
        }
    }

    finish(_ok, "OK");
}

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

static bool parseLongLong(const string& s, long long &v) {

    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 x = 0;
    for (; i < (int)s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        int d = c - '0';

        if (x > (LLONG_MAX - d) / 10) return false;
        x = x * 10 + d;
    }
    v = neg ? -x : x;
    return true;
}

static bool parseUnsignedLongLong(const string& s, unsigned long long &v) {
    if (s.empty()) return false;
    int i = 0;
    if (s[i] == '+') i++;
    if (i >= (int)s.size()) return false;
    unsigned long long x = 0;
    for (; i < (int)s.size(); i++) {
        char c = s[i];
        if (c < '0' || c > '9') return false;
        int d = c - '0';
        if (x > (ULLONG_MAX - (unsigned long long)d) / 10ULL) return false;
        x = x * 10ULL + (unsigned long long)d;
    }
    v = x;
    return true;
}

static bool validatePath(const vector<pair<int,int>>& p, int n) {
    if ((int)p.size() != 2 * n - 1) return false;
    if (p.front() != make_pair(1, 1)) return false;
    if (p.back() != make_pair(n, n)) return false;
    for (auto [x, y] : p) {
        if (x < 1 || x > n || y < 1 || y > n) return false;
    }
    for (int i = 1; i < (int)p.size(); i++) {
        int dx = p[i].first - p[i - 1].first;
        int dy = p[i].second - p[i - 1].second;
        if (!((dx == 1 && dy == 0) || (dx == 0 && dy == 1))) return false;
    }
    return true;
}

static vector<pair<int,int>> makePathFromPattern(int n, unsigned long long pattern) {
    int x = 1, y = 1;
    vector<pair<int,int>> p;
    p.reserve(2 * n - 1);
    p.push_back({x, y});
    const int moves = 2 * n - 2;
    for (int step = 0; step < moves; step++) {
        if (x == n) {
            y++;
        } else if (y == n) {
            x++;
        } else {
            bool goDown = ((pattern >> step) & 1ULL) != 0ULL;
            if (goDown) x++;
            else y++;
        }
        p.push_back({x, y});
    }
    return p;
}

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

    int n = inf.readInt(2, 25, "n");
    int q = inf.readInt(1, 1000, "q");
    vector<unsigned long long> patterns;
    patterns.reserve(q);
    for (int i = 0; i < q; i++) {
        long long v = inf.readLong(0LL, (long long)((1ULL<<62)-1), "pattern");
        patterns.push_back((unsigned long long)v);
    }

    query_limit = q;
    log_metrics();

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

    vector<vector<unsigned long long>> a(n, vector<unsigned long long>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            string tok;
            if (!readTokenSafe(tok)) finish(_pe, "Contestant didn't output full grid");
            unsigned long long val;
            if (!parseUnsignedLongLong(tok, val)) finish(_pe, "Grid value not an unsigned integer");
            if (val > 10000000000000000ULL) finish(_pe, "Grid value exceeds 1e16");
            a[i][j] = val;
        }
    }

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

    auto expectPathFromContestant = [&](const vector<pair<int,int>>& realPath) {

        vector<pair<int,int>> out;
        out.reserve(2*n-1);
        for (int i = 0; i < 2*n-1; i++) {
            string sx, sy;
            if (!readTokenSafe(sx)) finish(_pe, "Contestant ended early while outputting path");
            if (!readTokenSafe(sy)) finish(_pe, "Contestant ended early while outputting path");
            long long x, y;
            if (!parseLongLong(sx, x) || !parseLongLong(sy, y)) finish(_pe, "Path coordinates not integers");
            if (x < 1 || x > n || y < 1 || y > n) finish(_pe, "Path coordinates out of range");
            out.push_back({(int)x,(int)y});
        }
        if (!validatePath(out, n)) finish(_wa, "Answer path is not a valid monotone path");
        if (out != realPath) finish(_wa, "Path does not match");
    };

    auto computeSumOnPath = [&](const vector<pair<int,int>>& p) -> long long {
        __int128 s = 0;
        for (auto [x, y] : p) s += (__int128)a[x - 1][y - 1];
        if (s < 0 || s > (__int128)LLONG_MAX) finish(_fail, "sum overflow (interactor bug)");
        return (long long)s;
    };

    const long long hard_cap = max(200000LL, 10LL * query_limit);
    for (int qi = 0; qi < q; qi++) {
        vector<pair<int,int>> hiddenPath = makePathFromPattern(n, patterns[qi]);
        if (!validatePath(hiddenPath, n)) finish(_fail, "generated hidden path invalid (interactor bug)");

        long long k = computeSumOnPath(hiddenPath);
        cout << k << "\n";
        cout.flush();

        queries++;
        if (queries > hard_cap) finish(_pe, "too many interactions");

        expectPathFromContestant(hiddenPath);
    }
    finish(_ok, "OK");
}

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

static long long getSeedFromArgs(int argc, char** argv) {

    if (argc >= 2) {
        try {
            return stoll(string(argv[1]));
        } catch (...) {
            return 0;
        }
    }
    return 0;
}

static vector<pair<int,int>> randomPath(int n) {

    vector<int> moves;
    moves.reserve(2*n-2);
    for (int i = 0; i < n-1; i++) moves.push_back(0);
    for (int i = 0; i < n-1; i++) moves.push_back(1);

    for (int i = (int)moves.size()-1; i > 0; --i) {
        int j = rnd.next(0, i);
        swap(moves[i], moves[j]);
    }
    int x = 1, y = 1;
    vector<pair<int,int>> cells;
    cells.reserve(2*n-1);
    cells.push_back({x,y});
    for (int mv : moves) {
        if (mv == 0) y++;
        else x++;
        cells.push_back({x,y});
    }
    return cells;
}

static vector<pair<int,int>> adversarialZigzag(int n) {

    int x=1,y=1;
    vector<pair<int,int>> cells;
    cells.reserve(2*n-1);
    cells.push_back({x,y});

    int r = n-1, d = n-1;
    while (r > 0 || d > 0) {
        if (r > 0) { y++; r--; cells.push_back({x,y}); }
        if (d > 0) { x++; d--; cells.push_back({x,y}); }
    }
    return cells;
}

static vector<pair<int,int>> edgeThenEdge(int n, bool topThenRightCol) {
    int x=1,y=1;
    vector<pair<int,int>> cells;
    cells.reserve(2*n-1);
    cells.push_back({x,y});
    if (topThenRightCol) {

        for (int i=0;i<n-1;i++){ y++; cells.push_back({x,y}); }
        for (int i=0;i<n-1;i++){ x++; cells.push_back({x,y}); }
    } else {

        for (int i=0;i<n-1;i++){ x++; cells.push_back({x,y}); }
        for (int i=0;i<n-1;i++){ y++; cells.push_back({x,y}); }
    }
    return cells;
}

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

    string mode = opt<string>("mode", "non");
    long long seed = getSeedFromArgs(argc, argv);

    int n;
    int q;

    if (seed == 1) {
        n = 2; q = 3;
    } else if (seed == 2) {
        n = 25; q = 1000;
    } else if (seed == 3) {
        n = 25; q = 1;
    } else {
        n = opt<int>("n", 25);
        n = max(2, min(25, n));
        q = opt<int>("q", 1000);
        q = max(1, min(1000, q));
    }

    if (mode == "non") {

        cout << n << "\n";
        cout << q << "\n";

        vector<vector<pair<int,int>>> paths;
        paths.reserve(q);

        if (seed == 1) {

            paths.push_back(edgeThenEdge(n, true));
            paths.push_back(edgeThenEdge(n, false));
            paths.push_back(edgeThenEdge(n, true));
        } else if (seed == 2) {

            paths.push_back(edgeThenEdge(n, true));
            paths.push_back(edgeThenEdge(n, false));
            paths.push_back(adversarialZigzag(n));

            for (int i = 3; i < q; i++) {
                int t = rnd.next(0, 99);
                if (t < 8) paths.push_back(paths[rnd.next(0, (int)paths.size()-1)]);
                else if (t < 12) paths.push_back(adversarialZigzag(n));
                else paths.push_back(randomPath(n));
            }
        } else if (seed == 3) {

            paths.push_back(adversarialZigzag(n));
        } else {

            int pref = min(q, 5);
            if (pref >= 1) paths.push_back(edgeThenEdge(n, true));
            if (pref >= 2) paths.push_back(edgeThenEdge(n, false));
            if (pref >= 3) paths.push_back(adversarialZigzag(n));
            if (pref >= 4) paths.push_back(randomPath(n));
            if (pref >= 5) paths.push_back(randomPath(n));
            for (int i = (int)paths.size(); i < q; i++) {
                int t = rnd.next(0, 99);
                if (t < 10 && !paths.empty()) paths.push_back(paths[rnd.next(0, (int)paths.size()-1)]);
                else if (t < 15) paths.push_back(adversarialZigzag(n));
                else paths.push_back(randomPath(n));
            }
        }

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

            cout << (2*n - 1) << "\n";
            for (auto [x,y] : paths[i]) {
                cout << x << " " << y << "\n";
            }
        }
        return 0;
    } else if (mode == "adp") {

        cout << n << "\n";
        cout << q << "\n";

        auto emitK = [&](unsigned long long k) {

            unsigned long long LIM = (1ULL << 62) - 1;
            if (k > LIM) k = LIM;
            cout << (unsigned long long)k << "\n";
        };

        if (seed == 1) {

            emitK(0);
            emitK(1);
            emitK((1ULL<<20) + 3);
        } else if (seed == 2) {

            emitK(0);
            emitK((1ULL<<40) - 1);

            unsigned long long alt = 0;
            for (int b = 0; b < 60; b++) if (b % 2 == 1) alt |= (1ULL<<b);
            emitK(alt);

            unsigned long long alt2 = 0;
            for (int b = 0; b < 60; b++) if (b % 2 == 0) alt2 |= (1ULL<<b);
            emitK(alt2);

            for (int b = 0; b < 10; b++) emitK(1ULL << (b*6));
            int produced = 4 + 10;
            for (int i = produced; i < q; i++) {
                int t = rnd.next(0, 99);
                if (t < 10) {
                    int b = rnd.next(0, 60);
                    emitK(1ULL << b);
                } else if (t < 20) {

                    int b = rnd.next(1, 61);
                    unsigned long long base = 1ULL << (b-1);
                    unsigned long long delta = (unsigned long long)rnd.next(0, 7);
                    emitK(base - 1 + delta);
                } else if (t < 30) {

                    unsigned long long k = 0;
                    int bits = rnd.next(15, 35);
                    for (int j = 0; j < bits; j++) {
                        int b = rnd.next(0, 45);
                        k |= (1ULL<<b);
                    }
                    emitK(k);
                } else {

                    unsigned long long hi = (unsigned long long)rnd.next(0, (int)((1U<<30)-1));
                    unsigned long long lo = (unsigned long long)rnd.next(0, (int)((1U<<30)-1));
                    unsigned long long k = (hi<<30) ^ lo;
                    k &= ((1ULL<<60)-1);
                    emitK(k);
                }
            }
        } else if (seed == 3) {

            unsigned long long k = 0;
            for (int b = 0; b < 60; b += 3) k |= (1ULL<<b);
            emitK(k);
        } else {

            emitK(0);
            if (q >= 2) emitK((1ULL<<55) - 1);
            for (int i = 2; i < q; i++) {
                int t = rnd.next(0, 99);
                if (t < 15) {
                    int b = rnd.next(0, 60);
                    emitK(1ULL<<b);
                } else {
                    unsigned long long hi = (unsigned long long)rnd.next(0, (int)((1U<<30)-1));
                    unsigned long long lo = (unsigned long long)rnd.next(0, (int)((1U<<30)-1));
                    unsigned long long k = (hi<<30) + lo;
                    k &= ((1ULL<<60)-1);
                    emitK(k);
                }
            }
        }
        return 0;
    } else {

        cout << 2 << "\n";
        cout << 1 << "\n";
        cout << 3 << "\n";
        cout << "1 1\n1 2\n2 2\n";
        return 0;
    }
}