Bob has a simple undirected connected graph (without self-loops and multiple edges). He wants to learn whether his graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color) or not. As he is not very good at programming, he asked Alice for help. He does not want to disclose his graph to Alice, but he agreed that Alice can ask him some questions about the graph.

The only question that Alice can ask is the following: she sends $s$ — a subset of vertices of the original graph. Bob answers with the number of edges that have both endpoints in $s$. Since he doesn't want Alice to learn too much about the graph, he allows her to ask no more than $20000$ questions. Furthermore, he suspects that Alice might introduce false messages to their communication channel, so when Alice finally tells him whether the graph is bipartite or not, she also needs to provide a proof — either the partitions themselves or a cycle of odd length.

Your task is to help Alice to construct the queries, find whether the graph is bipartite.

Input

The first line contains a single integer $n$ ($1 \leq n \leq 600$) — the number of vertices in Bob's graph.

Interaction

First, read an integer $n$ ($1\leq n\leq 600$) — the number of vertices in Bob's graph.

To make a query, print two lines. First of which should be in the format "? k" ($1 \leq k \leq n$), where $k$ is the size of the set to be queried. The second line should contain $k$ space separated distinct integers $s_1, s_2, \dots, s_k$ ($1 \leq s_i \leq n$) — the vertices of the queried set.

After each query read a single integer $m$ ($0 \leq m \leq \frac{n(n-1)}{2}$) — the number of edges between the vertices of the set $\{s_i\}$.

You are not allowed to ask more than $20000$ queries.

If $m = -1$, it means that you asked more queries than allowed, or asked an invalid query. Your program should immediately terminate (for example, by calling exit(0)). You will receive Wrong Answer; it means that you asked more queries than allowed, or asked an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

After printing a query do not forget to print 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 know the answer, you need to print it.

The format of the answer depends on whether the graph is bipartite or not.

If the graph is bipartite, print two lines. The first should contain the letter "Y" (short for "YES") followed by a space, and then a single integer $s$ ($0 \leq s \leq n$) — the number of vertices in one of the partitions. Second line should contain $s$ integers $a_1, a_2, \dots, a_s$ — vertices belonging to the first partition. All $a_i$ must be distinct, and all edges in the main graph must have exactly one endpoint in the set $\{a_i\}$.

If the graph is not bipartite, print two lines. The first should contain the letter "N" (short for "NO") followed by a space, and then a single integer $l$ ($3 \leq l \leq n$) — the length of one simple cycle of odd length. Second line should contain $l$ integers $c_1, c_2, \dots, c_l$ — the vertices along the cycle. It must hold that for all $1 \leq i \leq l$, there is an edge $\{c_i, c_{(i \mod l)+1}\}$ in the main graph, and all $c_i$ are distinct.

If there are multiple possible answers, you may print any of them.

Examples

Input

```
4
4
0
1
1
1
0
```

Output

```
? 4
1 2 3 4
? 2
1 2
? 2
1 3
? 2
1 4
? 2
2 4
? 2
3 4
Y 2
1 2
```

Input

```
4
4
3
```

Output

```
? 4
1 4 2 3
? 3
1 2 4
N 3
2 1 4
```

Note

In the first case, Alice learns that there are $4$ edges in the whole graph. Over the course of the next three queries, she learns that vertex $1$ has two neighbors: $3$ and $4$. She then learns that while vertex $2$ is adjacent to $4$, the vertex $3$ isn't adjacent to $4$. There is only one option for the remaining edge, and that is $(2, 3)$. This means that the graph is a cycle on four vertices, with $(1, 2)$ being one partition and $(3, 4)$ being the second. Here, it would be also valid to output "3 4" on the second line.

In the second case, we also have a graph on four vertices and four edges. In the second query, Alice learns that there are three edges among vertices $(1, 2, 4)$. The only way this could possibly happen is that those form a triangle. As the triangle is not bipartite, Alice can report it as a proof. Notice that she does not learn where the fourth edge is, but she is able to answer Bob correctly anyway.

#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 readLL(long long& x) {
    return (cin >> x) ? true : false;
}

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

    const int MAXN = 605;

    int n = inf.readInt(1, 600, "n");
    int m = inf.readInt(0, n * (n - 1) / 2, "m");

    vector<bitset<MAXN>> adj(n + 1);
    vector<pair<int,int>> edges;
    edges.reserve(m);

    for (int i = 0; i < m; i++) {
        int u = inf.readInt(1, n, "u");
        int v = inf.readInt(1, n, "v");
        if (u == v) finish(_fail, "Hidden input has self-loop");
        if (u > v) swap(u, v);
        if (adj[u].test(v)) finish(_fail, "Hidden input has multiple edge");
        adj[u].set(v);
        adj[v].set(u);
        edges.push_back({u, v});
    }

    query_limit = 20000;
    log_metrics();

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

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

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

        if (cmd == "?") {
            if (++queries > hard_cap) {
                finish(_pe, "Hard cap exceeded");
            }

            long long kll;
            if (!readLL(kll)) finish(_pe, "Missing k after '?'");
            if (kll < 1 || kll > n) finish(_pe, "Invalid k in query");
            int k = (int)kll;

            vector<int> verts;
            verts.reserve(k);
            bitset<MAXN> mask;
            for (int i = 0; i < k; i++) {
                long long vll;
                if (!readLL(vll)) finish(_pe, "Not enough vertices in query");
                if (vll < 1 || vll > n) finish(_pe, "Vertex out of range in query");
                int v = (int)vll;
                if (mask.test(v)) finish(_pe, "Duplicate vertex in query");
                mask.set(v);
                verts.push_back(v);
            }

            long long cnt2 = 0;
            for (int v : verts) {
                cnt2 += (adj[v] & mask).count();
            }
            long long induced_edges = cnt2 / 2;

            cout << induced_edges << "\n" << flush;
            continue;
        }

        if (cmd == "Y") {
            long long sll;
            if (!readLL(sll)) finish(_pe, "Missing s after 'Y'");
            if (sll < 0 || sll > n) finish(_pe, "Invalid s after 'Y'");
            int s = (int)sll;

            vector<char> inA(n + 1, 0);
            for (int i = 0; i < s; i++) {
                long long vll;
                if (!readLL(vll)) finish(_pe, "Not enough vertices for partition");
                if (vll < 1 || vll > n) finish(_pe, "Partition vertex out of range");
                int v = (int)vll;
                if (inA[v]) finish(_pe, "Duplicate vertex in partition");
                inA[v] = 1;
            }

            for (auto [u, v] : edges) {
                if (inA[u] == inA[v]) {
                    finish(_wa, "Provided partition is not a valid bipartition");
                }
            }

            finish(_ok, "Correct: valid bipartition provided");
        }

        if (cmd == "N") {
            long long lll;
            if (!readLL(lll)) finish(_pe, "Missing l after 'N'");
            if (lll < 3 || lll > n) finish(_pe, "Invalid l after 'N'");
            int l = (int)lll;
            if ((l % 2) == 0) finish(_wa, "Provided cycle length is not odd");

            vector<int> cyc;
            cyc.reserve(l);
            vector<char> used(n + 1, 0);

            for (int i = 0; i < l; i++) {
                long long vll;
                if (!readLL(vll)) finish(_pe, "Not enough vertices for cycle");
                if (vll < 1 || vll > n) finish(_pe, "Cycle vertex out of range");
                int v = (int)vll;
                if (used[v]) finish(_wa, "Cycle is not simple (repeated vertex)");
                used[v] = 1;
                cyc.push_back(v);
            }

            for (int i = 0; i < l; i++) {
                int a = cyc[i];
                int b = cyc[(i + 1) % l];
                if (a == b) finish(_wa, "Cycle has repeated adjacent vertices");
                if (!adj[a].test(b)) {
                    finish(_wa, "Provided cycle edge does not exist in hidden graph");
                }
            }

            finish(_ok, "Correct: valid odd cycle provided");
        }

        finish(_pe, "Unknown command token");
    }
}

#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 constexpr int MAXN = 600;
static constexpr int BITS = MAXN + 1;
static constexpr int WORDS = (BITS + 63) / 64;

struct Bitset {
    array<uint64_t, WORDS> w{};

    inline void resetAll() {
        for (auto& x : w) x = 0;
    }

    inline void setBit(int idx) {
        w[(unsigned)idx >> 6] |= (1ULL << (idx & 63));
    }
    inline void resetBit(int idx) {
        w[(unsigned)idx >> 6] &= ~(1ULL << (idx & 63));
    }
    inline bool testBit(int idx) const {
        return (w[(unsigned)idx >> 6] >> (idx & 63)) & 1ULL;
    }

    inline long long countAnd(const Bitset& other) const {
        long long res = 0;
        for (int i = 0; i < WORDS; i++) res += __builtin_popcountll(w[i] & other.w[i]);
        return res;
    }

    inline void andInto(const Bitset& other) {
        for (int i = 0; i < WORDS; i++) w[i] &= other.w[i];
    }
};

static inline bool readTokenSafe(string& t) {
    return (cin >> t) ? true : false;
}

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

static inline void replyAndFlush(long long x) {
    cout << x << endl;
    cout.flush();
}

static inline void replyErrorAndFlush() {
    cout << -1 << endl;
    cout.flush();
}

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

struct FixedGraphJudge {
    int n = 0;
    long long m = 0;
    vector<Bitset> adj;

    bool hasEdge(int u, int v) const {
        if (u < 1 || v < 1 || u > n || v > n || u == v) return false;
        return adj[u].testBit(v);
    }

    long long answerQuery(const vector<int>& s) const {
        Bitset subset;
        subset.resetAll();
        for (int v : s) subset.setBit(v);
        long long sum = 0;
        for (int v : s) sum += adj[v].countAnd(subset);
        return sum / 2;
    }
};

struct AdaptiveBipartiteJudge {
    int n = 0;
    long long m_total = 0;

    vector<int> side;
    vector<Bitset> ones;
    vector<Bitset> unknown;

    long long fixedOneTotal = 0;
    long long undecidedGlobal = 0;

    bool hasEdge(int u, int v) const {
        if (u < 1 || v < 1 || u > n || v > n || u == v) return false;
        return ones[u].testBit(v);
    }

    long long answerQueryAndFixAllInside(const vector<int>& s) {
        Bitset rightSubset;
        rightSubset.resetAll();

        vector<int> leftList;
        leftList.reserve(s.size());

        for (int v : s) {
            if (side[v] == 1) rightSubset.setBit(v);
            else leftList.push_back(v);
        }
        sort(leftList.begin(), leftList.end());

        long long fixed1 = 0;
        long long unk = 0;

        for (int u : leftList) {
            fixed1 += ones[u].countAnd(rightSubset);
            unk += unknown[u].countAnd(rightSubset);
        }

        long long afterUndec = undecidedGlobal - unk;
        long long remBefore = m_total - fixedOneTotal;

        long long x_min = max(0LL, remBefore - afterUndec);
        long long x_max = min(unk, remBefore);

        if (x_min > x_max) {
            finish(_pe, "internal: infeasible range for adaptive response");
        }

        auto score = [&](long long x) -> long long {
            long long remAfter = remBefore - x;

            return llabs(2 * remAfter - afterUndec);
        };

        long long targetX = remBefore - (afterUndec / 2);
        long long bestX = x_min;
        long long bestScore = score(bestX);

        auto consider = [&](long long x) {
            if (x < x_min || x > x_max) return;
            long long sc = score(x);
            if (sc < bestScore || (sc == bestScore && x < bestX)) {
                bestScore = sc;
                bestX = x;
            }
        };

        consider(targetX);
        consider(targetX - 1);
        consider(targetX + 1);
        consider(x_max);

        long long needOnes = bestX;

        for (int u : leftList) {
            for (int wi = 0; wi < WORDS; wi++) {
                uint64_t x = unknown[u].w[wi] & rightSubset.w[wi];
                while (x) {
                    int b = __builtin_ctzll(x);
                    int v = wi * 64 + b;
                    x &= (x - 1);

                    if (v < 1 || v > n) continue;

                    unknown[u].resetBit(v);
                    unknown[v].resetBit(u);
                    if (needOnes > 0) {
                        ones[u].setBit(v);
                        ones[v].setBit(u);
                        needOnes--;
                    }
                }
            }
        }

        if (needOnes != 0) {
            finish(_pe, "internal: failed to assign required number of edges in subset");
        }

        fixedOneTotal += bestX;
        undecidedGlobal = afterUndec;

        return fixed1 + bestX;
    }

    void finalizeGraph() {
        long long need = m_total - fixedOneTotal;
        if (need < 0 || need > undecidedGlobal) {
            finish(_pe, "internal: cannot finalize to required total edge count");
        }

        for (int u = 1; u <= n && need > 0; u++) {
            if (side[u] != 0) continue;
            for (int wi = 0; wi < WORDS && need > 0; wi++) {
                uint64_t x = unknown[u].w[wi];
                while (x && need > 0) {
                    int b = __builtin_ctzll(x);
                    int v = wi * 64 + b;
                    x &= (x - 1);

                    if (v < 1 || v > n) continue;

                    unknown[u].resetBit(v);
                    unknown[v].resetBit(u);
                    ones[u].setBit(v);
                    ones[v].setBit(u);
                    need--;
                    fixedOneTotal++;
                }
            }
        }

        for (int u = 1; u <= n; u++) unknown[u].resetAll();

        if (need != 0) {
            finish(_pe, "internal: failed to reach required total edge count");
        }
        undecidedGlobal = 0;
    }
};

static void validateDistinctVerticesOrPE(const vector<int>& s, int n) {
    vector<unsigned char> seen(n + 1, 0);
    for (int v : s) {
        if (v < 1 || v > n) finish(_pe, "vertex out of range");
        if (seen[v]) finish(_pe, "duplicate vertex in set");
        seen[v] = 1;
    }
}

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

    int n = inf.readInt(1, 600, "n");
    long long m = inf.readLong(0, 1LL * n * (n - 1) / 2, "m");

    vector<pair<int, int>> edges;
    while (!inf.seekEof()) {
        int u = inf.readInt(1, n, "u");
        int v = inf.readInt(1, n, "v");
        edges.push_back({u, v});
    }

    query_limit = 20000;
    log_metrics();

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

    bool fixedGraphMode = ((long long)edges.size() == m);

    FixedGraphJudge fixed;
    AdaptiveBipartiteJudge adp;

    if (fixedGraphMode) {
        fixed.n = n;
        fixed.m = m;
        fixed.adj.assign(n + 1, Bitset{});
        for (int i = 1; i <= n; i++) fixed.adj[i].resetAll();

        vector<vector<unsigned char>> has(n + 1, vector<unsigned char>(n + 1, 0));
        for (auto [u, v] : edges) {
            if (u == v) finish(_pe, "hidden input has self-loop");
            if (has[u][v] || has[v][u]) finish(_pe, "hidden input has multiple edges");
            has[u][v] = has[v][u] = 1;
            fixed.adj[u].setBit(v);
            fixed.adj[v].setBit(u);
        }
    } else {

        if (!((int)edges.size() == max(0, n - 1))) {
            finish(_pe, "invalid hidden input format (expected fixed graph or adaptive schema)");
        }

        adp.n = n;
        adp.m_total = m;
        adp.side.assign(n + 1, -1);
        adp.ones.assign(n + 1, Bitset{});
        adp.unknown.assign(n + 1, Bitset{});
        for (int i = 1; i <= n; i++) {
            adp.ones[i].resetAll();
            adp.unknown[i].resetAll();
        }

        vector<vector<int>> treeAdj(n + 1);
        vector<vector<unsigned char>> mand(n + 1, vector<unsigned char>(n + 1, 0));

        for (auto [u, v] : edges) {
            if (u == v) finish(_pe, "hidden input has self-loop in mandatory edges");
            if (mand[u][v] || mand[v][u]) finish(_pe, "hidden input has duplicate mandatory edge");
            mand[u][v] = mand[v][u] = 1;
            treeAdj[u].push_back(v);
            treeAdj[v].push_back(u);
        }

        if (n >= 1) {
            queue<int> q;
            adp.side[1] = 0;
            q.push(1);
            while (!q.empty()) {
                int u = q.front();
                q.pop();
                for (int v : treeAdj[u]) {
                    if (adp.side[v] == -1) {
                        adp.side[v] = adp.side[u] ^ 1;
                        q.push(v);
                    } else if (adp.side[v] == adp.side[u]) {
                        finish(_pe, "hidden mandatory edges are not bipartite");
                    }
                }
            }
            for (int i = 1; i <= n; i++) {
                if (adp.side[i] == -1) finish(_pe, "hidden mandatory edges are disconnected");
            }
        }

        for (auto [u, v] : edges) {
            adp.ones[u].setBit(v);
            adp.ones[v].setBit(u);
        }
        adp.fixedOneTotal = (n <= 1) ? 0 : (long long)edges.size();

        long long leftCnt = 0, rightCnt = 0;
        for (int i = 1; i <= n; i++) {
            if (adp.side[i] == 0) leftCnt++;
            else rightCnt++;
        }
        long long totalCross = leftCnt * rightCnt;
        if (adp.m_total < (long long)edges.size() || adp.m_total > totalCross) {
            finish(_pe, "adaptive schema impossible: m outside feasible bipartite range");
        }

        for (int u = 1; u <= n; u++) {
            for (int v = 1; v <= n; v++) {
                if (u == v) continue;
                if (adp.side[u] == adp.side[v]) continue;
                if (mand[u][v]) continue;

                adp.unknown[u].setBit(v);
            }
        }

        for (int u = 1; u <= n; u++) {
            for (int wi = 0; wi < WORDS; wi++) {
                uint64_t x = adp.unknown[u].w[wi];
                while (x) {
                    int b = __builtin_ctzll(x);
                    int v = wi * 64 + b;
                    x &= (x - 1);
                    if (v < 1 || v > n) continue;
                    adp.unknown[v].setBit(u);
                }
            }
        }

        long long unk = 0;
        for (int u = 1; u <= n; u++) {
            if (adp.side[u] != 0) continue;
            unk += adp.unknown[u].countAnd(Bitset{});

            long long cnt = 0;
            for (int wi = 0; wi < WORDS; wi++) cnt += __builtin_popcountll(adp.unknown[u].w[wi]);
            unk += cnt;
        }

        unk = 0;
        for (int u = 1; u <= n; u++) {
            if (adp.side[u] != 0) continue;
            long long cnt = 0;
            for (int wi = 0; wi < WORDS; wi++) cnt += __builtin_popcountll(adp.unknown[u].w[wi]);
            unk += cnt;
        }
        adp.undecidedGlobal = unk;

        if (adp.fixedOneTotal + adp.undecidedGlobal != totalCross) {
            finish(_pe, "internal: cross-edge accounting mismatch");
        }
    }

    cout << n << endl;
    cout.flush();

    for (;;) {
        string t;
        if (!readTokenSafe(t)) {
            finish(_pe, "unexpected EOF from contestant");
        }

        if (t == "?") {
            long long kll;
            if (!readIntSafe(kll)) {
                replyErrorAndFlush();
                finish(_pe, "malformed query: missing k");
            }
            if (kll < 1 || kll > n) {
                replyErrorAndFlush();
                finish(_pe, "malformed query: k out of range");
            }
            int k = (int)kll;

            vector<int> s;
            s.reserve(k);
            for (int i = 0; i < k; i++) {
                long long vll;
                if (!readIntSafe(vll)) {
                    replyErrorAndFlush();
                    finish(_pe, "malformed query: missing vertex");
                }
                if (vll < 1 || vll > n) {
                    replyErrorAndFlush();
                    finish(_pe, "malformed query: vertex out of range");
                }
                s.push_back((int)vll);
            }

            {
                vector<unsigned char> seen(n + 1, 0);
                for (int v : s) {
                    if (seen[v]) {
                        replyErrorAndFlush();
                        finish(_pe, "malformed query: duplicate vertex");
                    }
                    seen[v] = 1;
                }
            }

            queries++;
            if (queries > hard_cap) {
                replyErrorAndFlush();
                finish(_pe, "too many queries (hard cap)");
            }

            long long ans = 0;
            if (fixedGraphMode) {
                ans = fixed.answerQuery(s);
            } else {
                ans = adp.answerQueryAndFixAllInside(s);
            }

            if (ans < 0 || ans > 1LL * n * (n - 1) / 2) {
                replyErrorAndFlush();
                finish(_pe, "internal: computed invalid answer");
            }

            replyAndFlush(ans);
            continue;
        }

        if (t == "Y") {
            long long sll;
            if (!readIntSafe(sll)) finish(_pe, "malformed final answer: missing s");
            if (sll < 0 || sll > n) finish(_pe, "malformed final answer: s out of range");
            int ssz = (int)sll;

            vector<int> part;
            part.reserve(ssz);
            for (int i = 0; i < ssz; i++) {
                long long vll;
                if (!readIntSafe(vll)) finish(_pe, "malformed final answer: missing vertex in partition");
                if (vll < 1 || vll > n) finish(_pe, "malformed final answer: vertex out of range");
                part.push_back((int)vll);
            }
            validateDistinctVerticesOrPE(part, n);

            vector<unsigned char> inA(n + 1, 0);
            for (int v : part) inA[v] = 1;

            if (!fixedGraphMode) adp.finalizeGraph();

            auto checkEdgeCross = [&](int u, int v) {
                if (inA[u] == inA[v]) {
                    finish(_wa, "claimed bipartition has same-side edge");
                }
            };

            if (fixedGraphMode) {

                for (int u = 1; u <= n; u++) {
                    for (int wi = 0; wi < WORDS; wi++) {
                        uint64_t x = fixed.adj[u].w[wi];
                        while (x) {
                            int b = __builtin_ctzll(x);
                            int v = wi * 64 + b;
                            x &= (x - 1);
                            if (v < 1 || v > n) continue;
                            if (v <= u) continue;
                            checkEdgeCross(u, v);
                        }
                    }
                }
            } else {

                for (int u = 1; u <= n; u++) {
                    if (adp.side[u] != 0) continue;
                    for (int wi = 0; wi < WORDS; wi++) {
                        uint64_t x = adp.ones[u].w[wi];
                        while (x) {
                            int b = __builtin_ctzll(x);
                            int v = wi * 64 + b;
                            x &= (x - 1);
                            if (v < 1 || v > n) continue;
                            checkEdgeCross(u, v);
                        }
                    }
                }
            }

            finish(_ok, "correct: valid bipartition");
        }

        if (t == "N") {
            long long lll;
            if (!readIntSafe(lll)) finish(_pe, "malformed final answer: missing l");
            if (lll < 3 || lll > n) finish(_pe, "malformed final answer: l out of range");
            int L = (int)lll;
            if ((L & 1) == 0) finish(_pe, "malformed final answer: l must be odd");

            vector<int> cyc;
            cyc.reserve(L);
            for (int i = 0; i < L; i++) {
                long long vll;
                if (!readIntSafe(vll)) finish(_pe, "malformed final answer: missing cycle vertex");
                if (vll < 1 || vll > n) finish(_pe, "malformed final answer: cycle vertex out of range");
                cyc.push_back((int)vll);
            }
            validateDistinctVerticesOrPE(cyc, n);

            if (!fixedGraphMode) adp.finalizeGraph();

            auto hasE = [&](int u, int v) -> bool {
                if (fixedGraphMode) return fixed.hasEdge(u, v);
                return adp.hasEdge(u, v);
            };

            for (int i = 0; i < L; i++) {
                int u = cyc[i];
                int v = cyc[(i + 1) % L];
                if (!hasE(u, v)) {
                    finish(_wa, "claimed odd cycle uses a non-edge");
                }
            }

            finish(_ok, "correct: valid odd cycle");
        }

        finish(_pe, "unexpected token from contestant");
    }
}

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

static long long parseSeed(int argc, char** argv) {
    if (argc < 2) return 1;
    char* endp = nullptr;
    long long s = strtoll(argv[1], &endp, 10);
    if (endp == argv[1]) return 1;
    return s;
}

static void shuffleVec(vector<int>& v, int l, int r) {
    for (int i = r; i > l; --i) {
        int j = rnd.next(l, i);
        swap(v[i], v[j]);
    }
}

static void shufflePairs(vector<pair<int,int>>& v) {
    for (int i = (int)v.size() - 1; i >= 1; --i) {
        int j = rnd.next(0, i);
        swap(v[i], v[j]);
    }
}

struct GraphBuilder {
    int n;
    vector<vector<unsigned char>> has;
    vector<pair<int,int>> edges;

    explicit GraphBuilder(int n_) : n(n_), has(n_ + 1, vector<unsigned char>(n_ + 1, 0)) {}

    bool addEdge(int u, int v) {
        if (u == v) return false;
        if (u > v) swap(u, v);
        if (has[u][v]) return false;
        has[u][v] = 1;
        edges.push_back({u, v});
        return true;
    }

    void applyPermutation(const vector<int>& perm) {
        vector<pair<int,int>> newEdges;
        newEdges.reserve(edges.size());
        for (auto [u, v] : edges) {
            int nu = perm[u], nv = perm[v];
            if (nu > nv) swap(nu, nv);
            newEdges.push_back({nu, nv});
        }
        sort(newEdges.begin(), newEdges.end());
        newEdges.erase(unique(newEdges.begin(), newEdges.end()), newEdges.end());

        has.assign(n + 1, vector<unsigned char>(n + 1, 0));
        edges.clear();
        edges.reserve(newEdges.size());
        for (auto [u, v] : newEdges) addEdge(u, v);
    }
};

static vector<int> makePermutation(int n) {
    vector<int> perm(n + 1);
    for (int i = 1; i <= n; i++) perm[i] = i;
    for (int i = n; i >= 2; --i) {
        int j = rnd.next(1, i);
        swap(perm[i], perm[j]);
    }
    return perm;
}

static GraphBuilder makeSmallCase(long long seed) {
    if (seed == 1) {
        GraphBuilder g(1);
        return g;
    }
    if (seed == 2) {
        GraphBuilder g(2);
        g.addEdge(1, 2);
        return g;
    }
    GraphBuilder g(3);
    g.addEdge(1, 2);
    g.addEdge(2, 3);
    g.addEdge(1, 3);
    return g;
}

static GraphBuilder makeBipartiteDense(int n, int targetM) {
    int a = n / 2;
    int b = n - a;

    vector<int> A(a), B(b);
    for (int i = 0; i < a; i++) A[i] = 1 + i;
    for (int i = 0; i < b; i++) B[i] = 1 + a + i;

    GraphBuilder g(n);

    vector<int> seq;
    seq.reserve(n);
    int i = 0, j = 0;
    while (i < a || j < b) {
        if (i < a) seq.push_back(A[i++]);
        if (j < b) seq.push_back(B[j++]);
    }
    for (int k = 0; k + 1 < n; k++) g.addEdge(seq[k], seq[k + 1]);

    int minNeed = (int)g.edges.size();
    int maxBip = a * b;
    targetM = max(targetM, minNeed);
    targetM = min(targetM, maxBip);

    vector<pair<int,int>> cand;
    cand.reserve((size_t)maxBip);
    for (int u : A) for (int v : B) cand.push_back({u, v});
    shufflePairs(cand);

    for (auto [u, v] : cand) {
        if ((int)g.edges.size() >= targetM) break;
        g.addEdge(u, v);
    }

    return g;
}

static GraphBuilder makeNonBipLongOddCycle(int n) {
    GraphBuilder g(n);
    if (n <= 2) {
        if (n == 2) g.addEdge(1, 2);
        return g;
    }

    int L = (n % 2 == 1) ? n : (n - 1);
    if (L < 3) L = 3;

    for (int i = 1; i < L; i++) g.addEdge(i, i + 1);
    g.addEdge(1, L);

    for (int v = L + 1; v <= n; v++) {
        int attach = rnd.next(1, L);
        g.addEdge(attach, v);
    }

    vector<int> perm = makePermutation(n);
    g.applyPermutation(perm);
    return g;
}

static GraphBuilder makeBipartiteSparseTree(int n) {
    GraphBuilder g(n);
    if (n <= 1) return g;
    vector<int> perm = makePermutation(n);
    for (int i = 2; i <= n; i++) {
        int parent = rnd.next(1, i - 1);
        g.addEdge(perm[parent], perm[i]);
    }
    return g;
}

static GraphBuilder makeNonBipDenseTriangleFreeOdd5(int n) {
    int a = n / 2;
    int b = n - a;
    if (a < 3 || b < 2) return makeNonBipLongOddCycle(n);

    vector<int> A(a), B(b);
    for (int i = 0; i < a; i++) A[i] = 1 + i;
    for (int i = 0; i < b; i++) B[i] = 1 + a + i;

    int u = A[0];
    int v = A[1];
    int w = A[2];

    vector<int> B1, B2;
    for (int i = 0; i < b; i++) {
        if (i < b / 2) B1.push_back(B[i]);
        else B2.push_back(B[i]);
    }
    if (B1.empty() || B2.empty()) return makeNonBipLongOddCycle(n);

    GraphBuilder g(n);

    for (int x : B1) g.addEdge(u, x);
    for (int x : B2) g.addEdge(v, x);

    for (int x : B) g.addEdge(w, x);
    for (int i = 3; i < a; i++) for (int x : B) g.addEdge(A[i], x);

    g.addEdge(u, v);

    vector<int> perm = makePermutation(n);
    g.applyPermutation(perm);
    return g;
}

static void outputNonInstance(const GraphBuilder& g) {
    cout << g.n << "\n";
    cout << (int)g.edges.size() << "\n";
    for (auto [u, v] : g.edges) cout << u << " " << v << "\n";
}

static void outputAdaptiveSchema(int n, int m, const vector<pair<int,int>>& treeEdges) {
    cout << n << "\n";
    cout << m << "\n";
    for (auto [u, v] : treeEdges) cout << u << " " << v << "\n";
}

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

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

    int nOpt = opt<int>("n", 600);
    int n = nOpt;
    n = max(1, min(600, n));

    if (seed >= 1 && seed <= 3) {
        if (mode == "non") {
            GraphBuilder g = makeSmallCase(seed);
            outputNonInstance(g);
            return 0;
        }
        if (mode == "adp") {
            int nSmall = (seed == 1 ? 1 : (seed == 2 ? 2 : 3));
            int mSmall = (seed == 1 ? 0 : (seed == 2 ? 1 : 3));
            vector<pair<int,int>> tree;
            for (int i = 1; i < nSmall; i++) tree.push_back({i, i + 1});
            outputAdaptiveSchema(nSmall, mSmall, tree);
            return 0;
        }
        quitf(_fail, "Unknown mode: %s", mode.c_str());
    }

    if (mode == "non") {
        int pattern = (int)(llabs(seed) % 4);
        GraphBuilder g(1);
        if (pattern == 0) {
            int a = n / 2;
            int b = n - a;
            int maxBip = a * b;
            int defTarget = maxBip - rnd.next(0, max(1, maxBip / 8));
            int targetM = opt<int>("m", defTarget);
            g = makeBipartiteDense(n, targetM);
        } else if (pattern == 1) {
            g = makeNonBipLongOddCycle(n);
        } else if (pattern == 2) {
            g = makeBipartiteSparseTree(n);
        } else {
            g = makeNonBipDenseTriangleFreeOdd5(n);
        }
        outputNonInstance(g);
        return 0;
    }

    if (mode == "adp") {
        int a = n / 2;
        int b = n - a;
        int maxBip = a * b;
        int pattern = (int)(llabs(seed) % 4);

        int mDefault;
        if (pattern == 0 || pattern == 3) {
            mDefault = maxBip - rnd.next(0, n);
        } else {
            mDefault = max(n - 1, 2 * n + rnd.next(0, n));
            mDefault = min(mDefault, maxBip);
        }
        int m = opt<int>("m", mDefault);
        m = max(n - 1, m);

        vector<pair<int,int>> tree;
        tree.reserve(max(0, n - 1));
        vector<int> perm = makePermutation(n);
        for (int i = 1; i < n; i++) tree.push_back({perm[i], perm[i + 1]});

        outputAdaptiveSchema(n, m, tree);
        return 0;
    }

    quitf(_fail, "Unknown mode: %s", mode.c_str());
}


This is an interactive problem.

You are a proud teacher at the Millennium Science School. Today, a student named Alice challenges you to a guessing game.

Alice is thinking of an integer from $1$ to $n$, and you must guess it by asking her some queries.

To make things harder, she says you must ask all the queries first, and she will ignore exactly $1$ query.

For each query, you choose an array of $k$ distinct integers from $1$ to $n$, where $k$ is even. Then, Alice will respond with one of the following:

* $\texttt{L}$: the number is one of the first $\frac{k}{2}$ elements of the array;
* $\texttt{R}$: the number is one of the last $\frac{k}{2}$ elements of the array;
* $\texttt{N}$: the number is not in the array;
* $\texttt{?}$: this query is ignored.

Alice is impatient, so you must find a strategy that minimizes the number of queries. Can you do it?

Formally, let $f(n)$ be the minimum number of queries required to determine Alice's number. Then you must find a strategy that uses exactly $f(n)$ queries.

Note that the interactor is adaptive, which means Alice's number is not fixed at the beginning and may depend on your queries. However, it is guaranteed that there exists at least one number that is consistent with Alice's responses.

We can show that $f(n) \leq 20$ for all $n$ such that $2 \le n \le 2 \cdot 10^5$.

Input

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

The only line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the maximum possible value of Alice's number.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Interaction

The interaction begins by reading the integer $n$.

Then, output a single integer $q$ ($1 \leq q \leq 20$) — the number of queries.

To ask a query, output a line in the following format:

* $k\,a_1\,a_2 \ldots a_k$ ($2 \leq k \leq n$, $k$ is even, $1 \leq a_i \leq n$, the $a_i$ are distinct) — the length of the array, and the array itself.

Once you've asked all $q$ queries, read a string $s$ ($|s| = q$) — the responses to the queries as described above.

When you know Alice's number, output a single integer $x$ ($1 \leq x \leq n$) — the value of the number.

Then, move on to the next test case, or terminate the program if there are no more test cases.

After outputting all $q$ queries, 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;
* flush(output) in Pascal;
* stdout.flush() in Python;
* See the documentation for other languages.

Note that even if you correctly determine Alice's number but use more than $f(n)$ queries, you will get Wrong answer.

Example

Input

```
2
3

?N

5

R?L
```

Output

```
2
2 1 2
2 1 2

3

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

1
```

Note

In the first test case, $n = 3$. We ask $2$ queries: $[1, 2]$, and $[1, 2]$ again.

* For the first query, Alice's response is $\texttt{?}$, which means this query is ignored.
* For the second query, Alice's response is $\texttt{N}$, which means her number is not in the array $[1, 2]$.

From the information above, we can determine that Alice's number is $3$.

It can be shown that all valid strategies for $n = 3$ require at least $2$ queries.

In the second test case, $n = 5$. We ask $3$ queries: $[3, 2, 4, 1]$, $[5, 4, 3, 1]$, and $[1, 5, 3, 4]$.

* For the first query, Alice's response is $\texttt{R}$, which means her number is in the array $[4, 1]$.
* For the second query, Alice's response is $\texttt{?}$, which means this query is ignored.
* For the third query, Alice's response is $\texttt{L}$, which means her number is in the array $[1, 5]$.

From the information above, we can determine that Alice's number is $1$.

It can be shown that all valid strategies for $n = 5$ require at least $3$ queries.

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

static bool parseLL(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    if (s[i] == '+') i++;
    if (i >= (int)s.size()) return false;
    bool neg = false;
    if (s[i] == '-') return false;
    long long val = 0;
    for (; i < (int)s.size(); i++) {
        unsigned char c = (unsigned char)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 v;
    if (!parseLL(tok, v)) finish(_pe, "Malformed integer token while reading " + what);
    return v;
}

static string readStringOrPE(const string& what) {
    string tok;
    if (!readTokenFromContestant(tok)) finish(_pe, "Unexpected EOF while reading " + what);
    return tok;
}

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

    int t = inf.readInt(1, 10000, "t");
    struct Case { int n; int x; int bad; };
    vector<Case> cases;
    cases.reserve(t);

    for (int i = 0; i < t; i++) {
        int n = inf.readInt(2, 200000, "n");
        int x = inf.readInt(1, n, "x");
        int bad = inf.readInt(1, 20, "bad");
        cases.push_back({n, x, bad});
    }

    query_limit = 20LL * t;
    log_metrics();

    cout << t << endl;

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

    for (int tc = 0; tc < t; tc++) {
        int n = cases[tc].n;
        int hidden_x = cases[tc].x;
        int bad_seed = cases[tc].bad;

        cout << n << endl;

        long long qll = readLLOrPE("q");
        if (qll < 1 || qll > 20) finish(_pe, "q must be in [1,20]");
        int q = (int)qll;

        queries += q;
        if (queries > hard_cap) finish(_pe, "Hard cap exceeded (too many queries)");

        int ignored = 1 + (bad_seed - 1) % q;

        string answers;
        answers.reserve(q);

        for (int i = 1; i <= q; i++) {
            long long kll = readLLOrPE("k");
            if (kll < 2 || kll > n) finish(_pe, "k out of range");
            if (kll % 2 != 0) finish(_pe, "k must be even");
            int k = (int)kll;

            vector<int> a(k);
            for (int j = 0; j < k; j++) {
                long long all = readLLOrPE("a_j");
                if (all < 1 || all > n) finish(_pe, "a_j out of range");
                a[j] = (int)all;
            }

            vector<int> b = a;
            sort(b.begin(), b.end());
            for (int j = 1; j < k; j++) {
                if (b[j] == b[j - 1]) finish(_pe, "Duplicate values in query array");
            }

            if (i == ignored) {
                answers.push_back('?');
                continue;
            }

            int pos = -1;
            for (int j = 0; j < k; j++) {
                if (a[j] == hidden_x) {
                    pos = j;
                    break;
                }
            }
            if (pos == -1) {
                answers.push_back('N');
            } else if (pos < k / 2) {
                answers.push_back('L');
            } else {
                answers.push_back('R');
            }
        }

        cout << answers << endl;

        long long guessll = readLLOrPE("answer x");
        if (guessll < 1 || guessll > n) finish(_pe, "Answer x out of range");
        int guess = (int)guessll;

        if (guess != hidden_x) finish(_wa, "Wrong answer");
    }

    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 << 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 bool readLongLong(long long& out) {
    if (!(cin >> out)) return false;
    return true;
}

static int f_min_queries(int n) {

    long long pw = 1;
    int q = 1;
    while (pw < n) {
        pw *= 3;
        q++;
        if (q > 60) break;
    }
    return q;
}

static int symToDigit(char c) {
    if (c == 'L') return 0;
    if (c == 'R') return 1;
    return 2;
}

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

    int t = 0;
    try {
        t = inf.readInt();
    } catch (...) {
        finish(_pe, "failed to read t from input");
    }
    if (t < 1 || t > 100000) finish(_pe, "t out of reasonable range");

    query_limit = 20LL * t;
    log_metrics();

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

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

    for (int tc = 1; tc <= t; tc++) {
        int n = 0;
        try {
            n = inf.readInt();
        } catch (...) {
            finish(_pe, "failed to read n from input");
        }
        if (n < 2 || n > 200000) finish(_pe, "n out of range");

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

        long long qll = 0;
        if (!readLongLong(qll)) finish(_pe, "failed to read q from contestant");
        if (qll < 1 || qll > 20) finish(_pe, "q must be in [1,20]");
        int q = (int)qll;

        int fq = f_min_queries(n);
        if (q != fq) finish(_wa, "wrong number of queries (must be minimal f(n))");

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

        vector<vector<char>> code(n + 1, vector<char>(q, 'N'));

        for (int qi = 0; qi < q; qi++) {
            long long kll = 0;
            if (!readLongLong(kll)) finish(_pe, "failed to read k");
            if (kll < 2 || kll > n) finish(_pe, "k out of range");
            int k = (int)kll;
            if (k % 2 != 0) finish(_pe, "k must be even");

            vector<int> a(k);
            vector<int> seen(n + 1, 0);
            for (int i = 0; i < k; i++) {
                long long xll = 0;
                if (!readLongLong(xll)) finish(_pe, "failed to read array element");
                if (xll < 1 || xll > n) finish(_pe, "array element out of range");
                int x = (int)xll;
                if (seen[x]) finish(_pe, "array elements must be distinct");
                seen[x] = 1;
                a[i] = x;
            }

            int h = k / 2;
            for (int i = 0; i < h; i++) code[a[i]][qi] = 'L';
            for (int i = h; i < k; i++) code[a[i]][qi] = 'R';
        }

        int bestJ = 0;
        int bestRep = 1;
        int bestSize = -1;

        vector<pair<long long, int>> keys;
        keys.reserve(n);

        for (int j = 0; j < q; j++) {
            keys.clear();
            for (int x = 1; x <= n; x++) {
                long long key = 0;
                for (int i = 0; i < q; i++) {
                    if (i == j) continue;
                    key = key * 3 + symToDigit(code[x][i]);
                }
                keys.emplace_back(key, x);
            }
            sort(keys.begin(), keys.end(), [](const auto& p1, const auto& p2) {
                if (p1.first != p2.first) return p1.first < p2.first;
                return p1.second < p2.second;
            });

            for (int idx = 0; idx < n; ) {
                int nxt = idx + 1;
                while (nxt < n && keys[nxt].first == keys[idx].first) nxt++;
                int sz = nxt - idx;
                int rep = keys[idx].second;
                if (sz > bestSize ||
                    (sz == bestSize && (j < bestJ || (j == bestJ && rep < bestRep)))) {
                    bestSize = sz;
                    bestJ = j;
                    bestRep = rep;
                }
                idx = nxt;
            }
        }

        string s(q, 'N');
        for (int i = 0; i < q; i++) s[i] = (i == bestJ ? '?' : code[bestRep][i]);

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

        long long xll = 0;
        if (!readLongLong(xll)) finish(_pe, "failed to read final answer x");
        if (xll < 1 || xll > n) finish(_pe, "final answer x out of range");
        int x = (int)xll;

        bool inGroup = true;
        for (int i = 0; i < q; i++) {
            if (i == bestJ) continue;
            if (code[x][i] != code[bestRep][i]) {
                inGroup = false;
                break;
            }
        }

        if (!(bestSize == 1 && inGroup)) {
            finish(_wa, "answer not uniquely determined by the interaction");
        }
    }

    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 bool isPowerOfTwo(int x) {
    return x > 0 && (x & (x - 1)) == 0;
}

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

    string mode = opt<string>("mode", "non");
    int maxN = opt<int>("maxn", 200000);

    ensuref(maxN >= 2, "maxn must be >= 2");
    ensuref(mode == "non" || mode == "adp", "mode must be 'non' or 'adp'");

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

    int n = 2;
    int x = 1;
    int bad = 1;

    if (seed == 1) {
        n = 2;
        x = 2;
        bad = 1;
    } else if (seed == 2) {
        n = 3;
        x = 3;
        bad = 2;
    } else if (seed == 3) {
        n = maxN;
        x = 1;
        bad = 20;
    } else {
        int pattern = rnd.next(0, 11);

        if (pattern <= 2) {

            int p = 1 << rnd.next(1, 17);
            int delta = rnd.next(-7, 7);
            n = clampInt((long long)p + (long long)delta, 2, maxN);
            if (isPowerOfTwo(n)) {
                int tweak = rnd.next(0, 1) ? 1 : -1;
                n = clampInt((long long)n + tweak, 2, maxN);
            }
        } else if (pattern <= 5) {

            n = maxN - rnd.next(0, 5000);
            if (n < 2) n = 2;
        } else if (pattern <= 7) {

            n = maxN - rnd.next(0, 2000);
            if (n < 2) n = 2;
            if ((n & 1) == 0) n = clampInt((long long)n - 1, 2, maxN);
        } else {

            int lo = max(2, maxN - 40000);
            n = rnd.next(lo, maxN);
        }

        int xtype = rnd.next(0, 9);
        if (xtype <= 2) x = 1;
        else if (xtype <= 5) x = n;
        else if (xtype <= 7) x = (n + 1) / 2;
        else x = rnd.next(1, n);

        bad = rnd.next(1, 20);
    }

    cout << 1 << "\n";
    if (mode == "non") {
        cout << n << " " << x << " " << bad << "\n";
    } else {
        cout << n << "\n";
    }

    return 0;
}


This is an interactive problem.

The jury has hidden a permutation$^\dagger$ $p$ of length $n$.

In one query, you can pick two integers $l$ and $r$ ($1 \le l < r \le n$) by paying $(r - l)^2$ coins. In return, you will be given the number of inversions$^\ddagger$ in the subarray $[p_l, p_{l + 1}, \ldots p_r]$.

Find the index of the maximum element in $p$ by spending at most $5 \cdot n^2$ coins.

Note: the grader is not adaptive: the permutation is fixed before any queries are made.

$^\dagger$ A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

$^\ddagger$ The number of inversions in an array is the number of pairs of indices $(i,j)$ such that $i < j$ and $a_i > a_j$. For example, the array $[10,2,6,3]$ contains $4$ inversions. The inversions are $(1,2),(1,3),(1,4)$, and $(3,4)$.

Input

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.

The only line of each test case contains a single integer $n$ ($2 \le n \le 2000$) — the length of the hidden permutation $p$.

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

Interaction

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

To make a query, output "? l r" ($1 \le l < r \le n$) without quotes. Afterwards, you should read one single integer — the answer for your query.

If you receive the integer $-1$ instead of an answer or a valid value of $n$, it means your program has made an invalid query, has exceed the limit of queries, or has given an incorrect answer on the previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

When you are ready to give the final answer, output "! i" ($1 \le i \le n$) without quotes — the index of the maximum of the hidden permutation. After solving a test case, your program should move to the next one immediately. After solving all test cases, your program should be terminated immediately.

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.

Example

Input

```
2
4

1

0

2

1
```

Output

```
? 1 3

? 3 4

! 4

? 1 2

! 1
```

Note

In the first test, the interaction proceeds as follows:

|  |  |  |
| --- | --- | --- |
| Solution | Jury | Explanation |
|  | 2 | There are $2$ test cases. |
|  | 4 | In the first test case, the hidden permutation is $[1,3,2,4]$, with length $4$. |
| ? 1 3 | 1 | The solution requests the number of inversions in the subarray $[1,3,2]$ by paying $4$ coins, and the jury responds with $1$. |
| ? 3 4 | 0 | The solution requests the number of inversions in the subarray $[2,4]$ by paying $1$ coin, and the jury responds with $0$. |
| ! 4 |  | The solution has somehow determined that $p_4 = 4$, and outputs it. Since the output is correct, the jury continues to the next test case. |
|  | 2 | In the second test case, the hidden permutation is $[2,1]$, with length $2$. |
| ? 1 2 | 1 | The solution requests the number of inversions in the subarray $[2,1]$ by paying $1$ coin, and the jury responds with $1$. |
| ! 1 |  | The solution has somehow determined that $p_1 = 2$, and outputs it. Since the output is correct and there are no more test cases, the jury and the solution exit. |

Note that the line breaks 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;

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 void sendMinusOne() {
    cout << -1 << "\n";
    cout.flush();
}

static int inversionCount(const vector<int>& p, int l, int r) {
    int inv = 0;
    for (int i = l - 1; i < r; i++) {
        for (int j = i + 1; j < r; j++) {
            if (p[i] > p[j]) inv++;
        }
    }
    return inv;
}

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

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

    int t = inf.readInt(1, 100, "t");
    vector<int> ns(t);
    vector<vector<int>> perms(t);

    long long sumN = 0;
    for (int tc = 0; tc < t; tc++) {
        int n = inf.readInt(2, 2000, "n");
        ns[tc] = n;
        sumN += n;

        vector<int> p(n);
        vector<int> seen(n + 1, 0);
        for (int i = 0; i < n; i++) {
            int v = inf.readInt(1, n, "p[i]");
            p[i] = v;
            if (++seen[v] != 1) finish(_fail, "invalid hidden permutation: duplicates");
        }
        perms[tc] = std::move(p);

        query_limit += 5LL * n * n;
    }
    if (sumN > 2000) finish(_fail, "invalid hidden input: sum(n) exceeds 2000");

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

    log_metrics();

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

    for (int tc = 0; tc < t; tc++) {
        const int n = ns[tc];
        const vector<int>& p = perms[tc];

        const long long budget = 5LL * n * n;
        long long spent = 0;

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

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

            if (tok == "?") {
                long long l_ll, r_ll;
                if (!(cin >> l_ll >> r_ll)) {
                    sendMinusOne();
                    finish(_pe, "malformed query");
                }
                if (!(1 <= l_ll && l_ll < r_ll && r_ll <= n)) {
                    sendMinusOne();
                    finish(_wa, "invalid query range");
                }
                int l = (int)l_ll, r = (int)r_ll;

                long long d = (long long)(r - l);
                long long cost = d * d;
                if (spent + cost > budget) {
                    sendMinusOne();
                    finish(_wa, "coin budget exceeded");
                }
                spent += cost;
                queries += cost;

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

                cout << inversionCount(p, l, r) << "\n";
                cout.flush();
            } else if (tok == "!") {
                long long idx_ll;
                if (!(cin >> idx_ll)) {
                    sendMinusOne();
                    finish(_pe, "malformed final answer");
                }
                if (!(1 <= idx_ll && idx_ll <= n)) {
                    sendMinusOne();
                    finish(_wa, "final answer out of range");
                }
                int idx = (int)idx_ll;
                if (p[idx - 1] != n) {
                    sendMinusOne();
                    finish(_wa, "wrong final answer");
                }
                break;
            } else {
                sendMinusOne();
                finish(_pe, "unexpected token (expected '?' or '!')");
            }
        }
    }

    finish(_ok, "OK");
    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 = opt<int>("n", -1);
    int t_opt = opt<int>("t", -1);

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

    if (n_opt != -1 && t_opt != -1) {

        int cnt = t_opt;
        if (cnt > 100) cnt = 100;

        long long total = (long long)cnt * n_opt;
        if (total > 2000) {
            if (n_opt >= 2000) {
                ns.push_back(2000);
            } else {
                cnt = 2000 / n_opt;
                for(int i = 0; i < cnt; ++i) ns.push_back(n_opt);
            }
        } else {
            for(int i = 0; i < cnt; ++i) ns.push_back(n_opt);
        }
    } else if (n_opt != -1) {

        ns.push_back(min(n_opt, 2000));
    } else if (t_opt != -1) {

        int cnt = min(t_opt, 100);

        ns = rnd.partition(cnt, 2000, 2);
    } else {

        if (seed == 1) {

            ns = {2};
        } else if (seed == 2) {

            ns = {2000};
        } else if (seed == 3) {

            ns = rnd.partition(100, 2000, 2);
        } else {

            int type = rnd.next(3);
            if (type == 0) {

                int cnt = rnd.next(1, 5);
                ns = rnd.partition(cnt, 2000, 2);
            } else if (type == 1) {

                int cnt = rnd.next(50, 100);
                ns = rnd.partition(cnt, 2000, 2);
            } else {

                int cnt = rnd.next(1, 100);
                int sum = rnd.next(max(cnt * 2, 1000), 2000);
                ns = rnd.partition(cnt, sum, 2);
            }
        }
    }

    cout << ns.size() << "\n";
    for (int n : ns) {
        cout << n << "\n";

        if (mode != "non" && mode != "adp") mode = "non";

        vector<int> p(n);
        iota(p.begin(), p.end(), 1);

        int structure = rnd.next(100);

        if (structure < 5) {

        } else if (structure < 10) {

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

            rotate(p.begin(), p.begin() + 1, p.end());
        } else if (structure < 20) {

            reverse(p.begin(), p.end());
            rotate(p.begin(), p.begin() + 1, p.end());
        } else if (structure < 25) {

            swap(p[n - 1], p[n / 2]);
        } else {

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

        for (int i = 0; i < n; ++i) {
            cout << p[i] << (i == n - 1 ? "" : " ");
        }
        cout << "\n";
    }

    return 0;
}


ALTER EGO - Yuta Imai vs Qlarabelle

This is an interactive problem.

There are two hidden non-negative integers $x$ and $y$ ($0 \leq x, y < 2^{30}$). You can ask no more than $2$ queries of the following form.

* Pick a non-negative integer $n$ ($0 \leq n < 2^{30}$). The judge will respond with the value of $(n \mathbin{|} x) + (n \mathbin{|} y)$, where $|$ denotes the bitwise OR operation.

After this, the judge will give you another non-negative integer $m$ ($0 \leq m < 2^{30}$). You must answer the correct value of $(m \mathbin{|} x) + (m \mathbin{|} y)$.

Input

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

Interaction

Two hidden integers $x$ and $y$ are chosen ($0 \leq x, y < 2^{30}$). Note that $x$ and $y$ might be different for different test cases.

The interactor in this task is not adaptive. In other words, the integers $x$ and $y$ do not change during the interaction.

To ask a query, pick an integer $n$ ($0 \leq n < 2^{30}$) and print only the integer $n$ to a line.

You will receive a single integer, the value of $(n \mathbin{|} x) + (n \mathbin{|} y)$.

You may make no more than $2$ queries of the following form.

After you finish your queries, output "!" in a line. You will receive an integer $m$ ($0 \leq m < 2^{30}$). Note that the value of $m$ is also fixed before interaction.

You must output only the value of $(m \mathbin{|} x) + (m \mathbin{|} y)$ in a line. Note that this line is not considered a query and is not taken into account when counting the number of queries asked.

After this, proceed to the next test case.

If you make more than $2$ queries during an interaction, your program must terminate immediately, and you will receive the Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

After printing a query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

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

Example

Input

```
2

3

4

1

0

1
```

Output

```
0

1!

4

0!

2
```

Note

In the first test, the interaction proceeds as follows.

|  |  |  |
| --- | --- | --- |
| Solution | Jury | Explanation |
|  | $\texttt{2}$ | There are 2 test cases. |
|  | $\texttt{}$ | In the first test case, $x=1$ and $y=2$. |
| $\texttt{0}$ | $\texttt{3}$ | The solution requests $(0 \mathbin{|} 1) + (0 \mathbin{|} 2)$, and the jury responds with $3$. |
| $\texttt{1}$ | $\texttt{4}$ | The solution requests $(1 \mathbin{|} 1) + (1 \mathbin{|} 2)$, and the jury responds with $4$. |
| $\texttt{!}$ | $\texttt{1}$ | The solution requests the value of $m$, and the jury responds with $1$. |
| $\texttt{4}$ |  | The solution knows that $(1 \mathbin{|} x) + (1 \mathbin{|} y)=4$ because of earlier queries. |
|  | $\texttt{}$ | In the second test case, $x=0$ and $y=0$. |
| $\texttt{0}$ | $\texttt{0}$ | The solution requests $(0 \mathbin{|} 0) + (0 \mathbin{|} 0)$, and the jury responds with $0$. |
| $\texttt{!}$ | $\texttt{1}$ | The solution requests the value of $m$, and the jury responds with $1$. |
| $\texttt{2}$ |  | The solution somehow deduces that $x=y=0$, so it responds with $(1 \mathbin{|} 0) + (1 \mathbin{|} 0)=2$. |

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;

static long long queries = 0;
static long long query_limit = 0;
static 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();
    cout << t << endl;

    query_limit = (long long)t * 2;

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

    log_metrics();

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

        long long x = inf.readInt();
        long long y = inf.readInt();
        long long m = inf.readInt();

        while (true) {

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

            string token;
            if (!(cin >> token)) {
                finish(_wa, "Unexpected EOF while expecting query or '!'");
            }

            if (token == "!") {
                break;
            }

            long long n;
            if (token == "?") {

                if (!(cin >> n)) {
                    finish(_wa, "Unexpected EOF after '?' token");
                }
            } else {

                try {
                    size_t idx;
                    n = stoll(token, &idx);
                    if (idx != token.size()) {
                        finish(_wa, "Invalid query format (trailing characters): " + token);
                    }
                } catch (...) {
                    finish(_wa, "Invalid query format (not an integer): " + token);
                }
            }

            if (n < 0 || n >= (1LL << 30)) {
                finish(_wa, "Query parameter 'n' out of range [0, 2^30)");
            }

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

            long long resp = (n | x) + (n | y);
            cout << resp << endl;
        }

        cout << m << endl;

        string ans_token;
        if (!(cin >> ans_token)) {
            finish(_wa, "Unexpected EOF while expecting answer");
        }

        if (ans_token == "!") {
            if (!(cin >> ans_token)) {
                finish(_wa, "Unexpected EOF after extra '!' prefix in answer");
            }
        }

        long long ans;
        try {
            size_t idx;
            ans = stoll(ans_token, &idx);
            if (idx != ans_token.size()) {
                finish(_wa, "Invalid answer format (trailing characters): " + ans_token);
            }
        } catch (...) {
            finish(_wa, "Invalid answer format (not an integer): " + ans_token);
        }

        long long correct = (m | x) + (m | y);
        if (ans != correct) {
            finish(_wa, "Incorrect answer for test case " + to_string(i + 1));
        }
    }

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

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

using namespace std;

const int MAX_VAL = (1 << 30) - 1;

struct TestCase {
    int x, y, m;
};

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

    registerGen(argc, argv, 1);

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

    int seed = atoi(argv[1]);

    vector<TestCase> cases;

    if (seed == 1) {

        cases.push_back({0, 0, 0});
        cases.push_back({MAX_VAL, MAX_VAL, MAX_VAL});
        cases.push_back({0, MAX_VAL, 0});
        cases.push_back({MAX_VAL, 0, MAX_VAL});
        cases.push_back({0, 0, MAX_VAL});
        cases.push_back({MAX_VAL, MAX_VAL, 0});
        cases.push_back({0, MAX_VAL, 1234567});

        cases.push_back({0x2AAAAAAA, 0x15555555, 0});
        cases.push_back({0x2AAAAAAA, 0x15555555, MAX_VAL});
    }
    else if (seed == 2) {

        for (int i = 0; i < 30; ++i) {
            cases.push_back({1 << i, 0, 1 << i});
            cases.push_back({0, 1 << i, 1 << i});
            cases.push_back({1 << i, 1 << i, 0});
        }
    }
    else if (seed == 3) {

        for (int i = 0; i < 100; ++i) {
            int x = rnd.next(0, MAX_VAL);
            int y = rnd.next(0, MAX_VAL) & ~x;
            int m = rnd.next(0, MAX_VAL);
            cases.push_back({x, y, m});
        }
        for (int i = 0; i < 100; ++i) {
            int y = rnd.next(0, MAX_VAL);
            int x = y & rnd.next(0, MAX_VAL);
            int m = rnd.next(0, MAX_VAL);
            cases.push_back({x, y, m});
        }
    }
    else {

        int t = rnd.next(1000, 10000);
        for (int i = 0; i < t; ++i) {
            int x = rnd.next(0, MAX_VAL);
            int y = rnd.next(0, MAX_VAL);
            int m = rnd.next(0, MAX_VAL);

            int type = rnd.next(20);
            if (type == 0) y = x;
            else if (type == 1) x = 0;
            else if (type == 2) m = x | y;
            else if (type == 3) m = 0;

            cases.push_back({x, y, m});
        }
    }

    if (cases.empty()) {
        cases.push_back({17, 17, 17});
    }

    cout << cases.size() << endl;

    for (const auto& c : cases) {
        if (adaptive) {

            cout << c.m << endl;
        } else {

            cout << c.x << " " << c.y << " " << c.m << endl;
        }
    }

    return 0;
}


All problems in this contest share the same statement, the only difference is the test your solution runs on. For further information on scoring please refer to "Scoring" section of the statement.

This is an interactive problem.

Imagine you are a treasure hunter, a very skillful one. One day you came across an ancient map which could help you to become rich. The map shows multiple forestry roads, and at each junction there is a treasure. So, you start your journey hoping to retrieve all the hidden treasures, but you don't know yet that there is a wicked wizard standing against you and craving to tangle up these roads and impede your achievements.

The treasure map is represented as an undirected graph in which vertices correspond to junctions and edges correspond to roads. Your path begins at a certain fixed vertex with a label known to you. Every time you come to a vertex that you have not been to before, you dig up a treasure chest and put a flag in this vertex. At the initial vertex you'll find a treasure chest immediately and, consequently, you'll put a flag there immediately as well.

When you are standing at the junction you can see for each of the adjacent vertices its degree and if there is a flag there. There are no other things you can see from there. Besides, the power of the wicked wizard is so great that he is able to change the location of the roads and junctions on the map without changing the graph structure. Therefore, the sequence of the roads coming from the junction $v$ might be different each time you come in the junction $v$. However, keep in mind that the set of adjacent crossroads does not change, and you are well aware of previously dug treasures at each adjacent to $v$ vertex.

Your goal is to collect treasures from all vertices of the graph as fast as you can. Good luck in hunting!

Interaction

On the first line the interactor prints an integer $t$ ($1 \leq t \leq 5$) — the number of maps for which you need to solve the problem.

Then for each of the $t$ maps interactor firstly prints the graph description and after that interaction on this map starts. The map description is given in the following format.

The first line contains four integers $n, m, start, base\_move\_count$ ($2 \leq n \leq 300$, $1 \leq m \leq min(\frac{n(n-1)}{2}, 25n)$, $1 \leq start \leq n$, $1000 \leq base\_move\_count \leq 30000$) — the number of vertices and edges in the graph, the label of the vertex where you start the journey and some base move count, on which the score for the map depends. It's guaranteed that the jury has a solution traversing the map using not more than $base\_move\_count$ moves with high probability.

The next $m$ lines contain descriptions of the edges of the graph $u, v$ ($1 \leq u, v \leq n$, $u \neq v$). It is guaranteed that the graph is connected, does not contain multiple edges and the degrees of all vertices do not exceed 50.

You can find map descriptions for all tests in the archive 'map\_descriptions.zip' which you can find in any of the archives 'problem-X-materials.zip' in the section "Contest materials" — they are all the same.

After that the interaction begins. The interactor prints vertex descriptions in the following format:

R~d~deg\_1~flag\_1~deg\_2~flag\_2 \ldots deg\_d~flag\_d, where $d$ is the degree of the current vertex, $deg_i$ is the degree of the $i$-th vertex adjacent to the current one, and $flag_i$ (0 or 1) is an indicator if the $i$-th adjacent vertex contains a flag. The order of neighbors in the vertex description is chosen by the interactor uniformly at random independently each time. Please keep in mind that you are not given the actual labels of adajacent vertices.

In response to the description of the vertex you should print a single integer $i$ ($1 \leq i \leq d$), which means that you have chosen the vertex with description $deg_i~flag_i$. Remember to use the flush operation after each output. If your output is invalid, you will get a "Wrong Answer" verdict.

When you have visited all the vertices of the graph at least once, the interactor prints the string "AC" instead of the vertex description. If you use more than $2 \cdot base\_move\_count$ moves, the interactor prints the string "F". In both cases, you have to either start reading the description of the next map, or terminate the program, if it has been the last map in the test.

Below the example of interaction is presented. Note that the test from the example is not the same that your solution will be tested on.

```
|  |  |
| --- | --- |
| Interactor | Solution |
| 1 |  |
| 3 3 1 1000 |  |
| 1 2 |  |
| 2 3 |  |
| 3 1 |  |
| R 2 2 0 2 0 |  |
|  | 1 |
| R 2 2 0 2 1 |  |
|  | 2 |
| R 2 2 0 2 1 |  |
|  | 1 |
| AC |  |
```

Scoring

All problems of this contest share the same statement and differ only in the test. Each problem contains one test. Map descriptions for the test are available to look at in the archive.

Each test consists of several maps.

The solution score for the problem will be $0$ in case your solution for some map failed to get an answer "AC" or "F". If the solution correctly interacted with the interactor on all $t$ maps, the score for the task will be equal to the sum of the scores for each of the maps.

If you have successfully passed all vertices of a graph with $n$ vertices using $moves$ moves, the score for the map is calculated as follows. Denote

base\\_fraction=\frac{base\\_move\\_count + 1}{n},sol\\_fraction=\frac{moves+1}{n},c=\frac{90}{\sqrt{base\\_fraction - 1}}.

Then:

* if $moves \leq base\_move\_count$, you get $100-c \sqrt{sol\_fraction - 1}$ points.
* if $base\_move\_count < moves \leq 2 \cdot base\_move\_count$, you get $20 - \frac{10\cdot(moves + 1)}{base\_move\_count + 1}$ points.

If you use more than $2 \cdot base\_move\_count$ moves, you get 0 points for the map.

For each problem the solution with the highest score is chosen. Please note that the maximum is chosen for the entire test as a whole, not for each separate map.

The final result of the participant is the sum of points for each of the problems.

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

using namespace std;

static long long queries = 0;
static long long query_limit = 0;
static mt19937 rng(42);

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 int read_choice_index() {
    string token;
    if (!(cin >> token)) {
        finish(_wa, "Unexpected EOF while reading move");
    }
    if (token.empty()) {
        finish(_wa, "Invalid move token");
    }
    for (char ch : token) {
        if (ch < '0' || ch > '9') {
            finish(_wa, "Invalid move token");
        }
    }
    try {
        size_t pos = 0;
        long long v = stoll(token, &pos);
        if (pos != token.size() || v > numeric_limits<int>::max()) {
            finish(_wa, "Invalid move token");
        }
        return (int)v;
    } catch (...) {
        finish(_wa, "Invalid move token");
    }
    return -1;
}

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

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

    int t = inf.readInt(1, 5, "t");
    cout << t << endl;
    cout.flush();

    for (int tc = 0; tc < t; ++tc) {
        int n = inf.readInt(2, 300, "n");
        int max_m = (int)min(1LL * n * (n - 1) / 2, 25LL * n);
        int m = inf.readInt(1, max_m, "m");
        int start = inf.readInt(1, n, "start");
        int base_move_count = inf.readInt(1000, 30000, "base_move_count");

        long long map_limit = 2LL * base_move_count;
        query_limit += map_limit;
        if (tc == 0) log_metrics();

        vector<vector<int>> adj(n + 1);
        vector<int> deg(n + 1, 0);
        vector<pair<int, int>> edges;
        edges.reserve(m);

        for (int i = 0; i < m; ++i) {
            int u = inf.readInt(1, n, "u");
            int v = inf.readInt(1, n, "v");
            adj[u].push_back(v);
            adj[v].push_back(u);
            deg[u]++;
            deg[v]++;
            edges.push_back({u, v});
        }

        cout << n << " " << m << " " << start << " " << base_move_count << endl;
        for (const auto& e : edges) {
            cout << e.first << " " << e.second << endl;
        }
        cout.flush();

        vector<char> visited(n + 1, 0);
        visited[start] = 1;
        int visited_count = 1;
        int cur = start;
        long long moves = 0;

        while (true) {
            if (visited_count == n) {
                cout << "AC" << endl;
                cout.flush();
                break;
            }
            if (moves > map_limit) {
                cout << "F" << endl;
                cout.flush();
                break;
            }

            vector<int> neighbors = adj[cur];
            shuffle(neighbors.begin(), neighbors.end(), rng);

            cout << "R " << neighbors.size();
            for (int v : neighbors) {
                cout << " " << deg[v] << " " << (visited[v] ? 1 : 0);
            }
            cout << endl;
            cout.flush();

            int choice = read_choice_index();
            if (choice < 1 || choice > (int)neighbors.size()) {
                finish(_wa, format("Invalid choice %d (expected 1..%d)", choice, (int)neighbors.size()));
            }

            cur = neighbors[choice - 1];
            moves++;
            queries++;
            if (queries % 200 == 0) log_metrics();

            if (!visited[cur]) {
                visited[cur] = 1;
                visited_count++;
            }
        }
    }

    finish(_ok, "All maps processed");
    return 0;
}

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

using namespace std;

static long long queries = 0;
static long long query_limit = 0;
static mt19937 rng(239);

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 int read_choice_index() {
    string token;
    if (!(cin >> token)) {
        finish(_wa, "Unexpected EOF while reading move");
    }
    if (token.empty()) {
        finish(_wa, "Invalid move token");
    }
    for (char ch : token) {
        if (ch < '0' || ch > '9') {
            finish(_wa, "Invalid move token");
        }
    }
    try {
        size_t pos = 0;
        long long v = stoll(token, &pos);
        if (pos != token.size() || v > numeric_limits<int>::max()) {
            finish(_wa, "Invalid move token");
        }
        return (int)v;
    } catch (...) {
        finish(_wa, "Invalid move token");
    }
    return -1;
}

struct DisplayEntry {
    int v;
    int degree;
    int flag;
};

static void run_map(int n, int m, int start, int base_move_count, const vector<pair<int, int>>& edges) {
    vector<vector<int>> adj(n + 1);
    vector<int> deg(n + 1, 0);
    for (const auto& e : edges) {
        adj[e.first].push_back(e.second);
        adj[e.second].push_back(e.first);
        deg[e.first]++;
        deg[e.second]++;
    }

    cout << n << " " << m << " " << start << " " << base_move_count << endl;
    for (const auto& e : edges) {
        cout << e.first << " " << e.second << endl;
    }
    cout.flush();

    long long map_limit = 2LL * base_move_count;
    vector<char> visited(n + 1, 0);
    visited[start] = 1;
    int visited_count = 1;
    int cur = start;
    long long moves = 0;

    while (true) {
        if (visited_count == n) {
            cout << "AC" << endl;
            cout.flush();
            return;
        }
        if (moves > map_limit) {
            cout << "F" << endl;
            cout.flush();
            return;
        }

        const vector<int>& neighbors = adj[cur];
        int d = (int)neighbors.size();

        vector<DisplayEntry> display;
        display.reserve(d);
        for (int v : neighbors) {
            display.push_back({v, deg[v], visited[v] ? 1 : 0});
        }
        shuffle(display.begin(), display.end(), rng);

        cout << "R " << d;
        for (const auto& e : display) {
            cout << " " << e.degree << " " << e.flag;
        }
        cout << endl;
        cout.flush();

        int choice = read_choice_index();
        if (choice < 1 || choice > d) {
            finish(_wa, format("Invalid choice %d (expected 1..%d)", choice, d));
        }

        cur = display[choice - 1].v;
        if (!visited[cur]) {
            visited[cur] = 1;
            visited_count++;
        }

        moves++;
        queries++;
        if (queries % 200 == 0) log_metrics();
        if (queries > 2000000) finish(_pe, "Hard query cap exceeded");
    }
}

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

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

    int t = inf.readInt(1, 5, "t");
    cout << t << endl;
    cout.flush();

    for (int tc = 0; tc < t; ++tc) {
        int n = inf.readInt(2, 300, "n");
        int max_m = (int)min(1LL * n * (n - 1) / 2, 25LL * n);
        int m = inf.readInt(1, max_m, "m");
        int start = inf.readInt(1, n, "start");
        int base_move_count = inf.readInt(1000, 30000, "base_move_count");

        query_limit += 2LL * base_move_count;
        if (tc == 0) log_metrics();

        vector<pair<int, int>> edges;
        edges.reserve(m);
        for (int i = 0; i < m; ++i) {
            int u = inf.readInt(1, n, "u");
            int v = inf.readInt(1, n, "v");
            edges.push_back({u, v});
        }

        run_map(n, m, start, base_move_count, edges);
    }

    finish(_ok, "All maps processed");
    return 0;
}

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

using namespace std;

static vector<pair<int, int>> gen_circulant_regular_graph(int n, int k) {

    if (k < 1) k = 1;
    if (k > 50) k = 50;
    if (k >= n) k = n - 1;
    if (k % 2 != 0) k--;
    if (k < 2) k = 2;

    vector<int> perm(n + 1);
    for (int i = 1; i <= n; ++i) perm[i] = i;
    shuffle(perm.begin() + 1, perm.end());

    set<pair<int, int>> edges;
    int half = k / 2;
    for (int i = 1; i <= n; ++i) {
        for (int delta = 1; delta <= half; ++delta) {
            int j = i + delta;
            if (j > n) j -= n;
            int u = perm[i];
            int v = perm[j];
            if (u > v) swap(u, v);
            edges.insert({u, v});
        }
    }

    return vector<pair<int, int>>(edges.begin(), edges.end());
}

static vector<pair<int, int>> gen_circulant_regular_graph_on_labels(const vector<int>& labels, int k) {

    int n = (int)labels.size();
    if (n <= 1) return {};

    if (k > 50) k = 50;
    if (k >= n) k = n - 1;
    if (k % 2 != 0) k--;
    if (k < 2) k = 2;

    vector<int> perm = labels;
    shuffle(perm.begin(), perm.end());

    set<pair<int, int>> edges;
    int half = k / 2;
    for (int i = 0; i < n; ++i) {
        for (int delta = 1; delta <= half; ++delta) {
            int j = i + delta;
            if (j >= n) j -= n;
            int u = perm[i];
            int v = perm[j];
            if (u > v) swap(u, v);
            edges.insert({u, v});
        }
    }

    return vector<pair<int, int>>(edges.begin(), edges.end());
}

struct TwoBlockGraph {
    vector<pair<int, int>> edges;
    int start = 1;
};

static TwoBlockGraph gen_two_block_bottleneck_graph(int n, int internal_k) {

    TwoBlockGraph out;
    if (n < 4) {
        out.edges = {{1, 2}, {2, 3}, {3, 4}};
        out.start = 1;
        return out;
    }

    int n1 = n / 2;
    int n2 = n - n1;

    internal_k = min(internal_k, 50);
    if (internal_k % 2 != 0) internal_k--;
    if (internal_k < 2) internal_k = 2;
    internal_k = min(internal_k, min(n1 - 1, n2 - 1));
    if (internal_k % 2 != 0) internal_k--;
    if (internal_k < 2) internal_k = 2;

    vector<int> labels_a(n1), labels_b(n2);
    iota(labels_a.begin(), labels_a.end(), 1);
    iota(labels_b.begin(), labels_b.end(), n1 + 1);

    vector<pair<int, int>> edges;
    {
        vector<pair<int, int>> ea = gen_circulant_regular_graph_on_labels(labels_a, internal_k);
        vector<pair<int, int>> eb = gen_circulant_regular_graph_on_labels(labels_b, internal_k);
        edges.reserve(ea.size() + eb.size() + 1);
        edges.insert(edges.end(), ea.begin(), ea.end());
        edges.insert(edges.end(), eb.begin(), eb.end());
    }

    int u = labels_a[rnd.next(0, n1 - 1)];
    int v = labels_b[rnd.next(0, n2 - 1)];
    if (u > v) swap(u, v);
    edges.push_back({u, v});

    vector<int> perm(n + 1);
    for (int i = 1; i <= n; ++i) perm[i] = i;
    shuffle(perm.begin() + 1, perm.end());

    for (auto& e : edges) {
        int a = perm[e.first];
        int b = perm[e.second];
        if (a > b) swap(a, b);
        e = {a, b};
    }
    sort(edges.begin(), edges.end());
    edges.erase(unique(edges.begin(), edges.end()), edges.end());

    int start_orig = labels_a[rnd.next(0, n1 - 1)];
    out.start = perm[start_orig];
    out.edges = std::move(edges);
    return out;
}

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

    registerGen(argc, argv, 1);

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

    int t = 5;
    cout << t << endl;

    for (int ti = 0; ti < t; ++ti) {
        int n = (mode == "adp") ? rnd.next(290, 300) : rnd.next(80, 300);

        int k;
        if (mode == "adp") {

            k = 48;
        } else {

            int max_k = min(50, n - 1);
            int min_k = min(10, max_k);
            k = rnd.next(min_k / 2, max_k / 2) * 2;
            if (k < 2) k = 2;
            if (k >= n) k = n - 1 - ((n - 1) % 2);
            if (k < 2) k = 2;
        }

        vector<pair<int, int>> edges;
        int m = 0;
        int start = 1;
        if (mode == "adp") {
            TwoBlockGraph g = gen_two_block_bottleneck_graph(n, k);
            edges = std::move(g.edges);
            m = (int)edges.size();
            start = g.start;
        } else {
            edges = gen_circulant_regular_graph(n, k);
            m = (int)edges.size();
            start = rnd.next(1, n);
        }

        int base_move_count;
        if (mode == "adp") {
            base_move_count = 1000;
        } else {
            int base_low = 12 * n;
            int base_high = 18 * n;
            base_move_count = rnd.next(max(1000, base_low), min(30000, max(1000, base_high)));
        }

        cout << n << " " << m << " " << start << " " << base_move_count << endl;
        for (const auto& e : edges) {
            cout << e.first << " " << e.second << endl;
        }
    }

    return 0;
}