Problem: cf2106_g1
Difficulty: medium
Categories: graph, search
Time limit: 3000 ms, memory limit: 256 MB

This is the easy version of the problem. The only difference between the two versions is that in this version, it is guaranteed that every node is adjacent to node $1$.

This problem is interactive.

Baudelaire is very rich, so he bought a tree of size $n$ that is rooted at some arbitrary node. Additionally, every node has a value of $1$ or $-1$. In this version, every node is adjacent to node $1$. However, please note that node $1$ is not necessarily the root.

Cow the Nerd saw the tree and fell in love with it. However, computer science doesn't pay him enough, so he can't afford to buy it. Baudelaire decided to play a game with Cow the Nerd, and if he won, he would gift him the tree.

Cow the Nerd does not know which node is the root, and he doesn't know the values of the nodes either. However, he can ask Baudelaire queries of two types:

* $1$ $k$ $u_1$ $u_2$ $...$ $u_k$: Let $f(u)$ be the sum of the values of all nodes in the path from the root of the tree to node $u$. Cow the Nerd may choose an integer $k$ $(1 \le k \le n)$ and $k$ nodes $u_1, u_2, ..., u_k$, and he will receive the value $f(u_1) + f(u_2) + ... + f(u_k)$.
* $2$ $u$: Baudelaire will toggle the value of node $u$. Specifically, if the value of $u$ is $1$ it will become $-1$, and vice versa.

Cow the Nerd wins if he guesses the value of every node correctly (the values of the final tree, after performing the queries) within $n + 200$ total queries. Can you help him win?

Input

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

The first line of each test case contains a single integer $n$ $(2 \le n \le 10^3)$, the size of the tree.

Each of the next $n-1$ lines contains two integers $u$ and $v$ $(1 \le u, v \le n, u \neq v)$, denoting an edge between nodes $u$ and $v$ in the tree. In this version, it is guaranteed that either $u = 1$ or $v = 1$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^3$ and that each graph provided is a valid tree.

Interaction

To ask a query of type $1$, output a line in the following format (without the quotes):

* "? 1 k $u_1$ $u_2$ $...$ $u_k$", ($1 \le k, u_i \le n$)

The jury will return a single integer, $f(u_1) + f(u_2) + ... + f(u_k)$.

To ask a query of type $2$, output a line in the following format:

* "? 2 $u$" ($1 \le u \le n$)

The jury will toggle the value of node $u$: if its value is $1$ it will become $-1$ and vice versa.

When you have found the answer, output a single line in the following format:

* "! $v_1, v_2, ..., v_n$" ($v_i = 1$ or $v_i = -1$, and $v_i$ is the value of node $i$ after performing the queries)

After that, proceed to process the next test case or terminate the program if it was the last test case. Printing the answer does not count as a query.

The interactor is not adaptive, meaning that the values of the tree are known before the participant asks the queries.

If your program makes more than $n + 200$ queries, your program should immediately terminate to receive the verdict Wrong Answer. 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 may get the Idleness Limit Exceeded verdict. 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

```
1
4
1 2
3 1
1 4

0

-6
```

Output

```
? 1 3 1 2 3

? 2 2
? 1 3 1 2 3

! -1 -1 -1 1
```

Note

In the example, the root of the tree is node $2$, and the values of the nodes are $[-1, 1, -1, 1]$. Therefore, $f(1) = 0, f(2) = 1, f(3) = -1, f(4) = 1$.

First, we query about the sum $f(1) + f(2) + f(3)$, so we receive the value $0$. Then, we toggle the value of node $2$, and the values are: $[-1, -1, -1, 1]$. Therefore, $f(1) = -2, f(2) = -1, f(3) = -3, f(4) = -1$, and $f(1) + f(2) + f(3) = -6$.

Finally, we figure out that the values of the nodes are $[-1, -1, -1, 1]$, so we answer that.

Note that this is just an explanation of how the queries work, and it is not supposed to use any specific strategy to solve the problem.

Non-adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;


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




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


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


int n;
vector<vector<int>> adj;
int root_node;
vector<int> vals;       
vector<int> parent;     




void build_tree(int r) {
    parent.assign(n + 1, 0);
    queue<int> q;
    q.push(r);
    vector<bool> vis(n + 1, false);
    vis[r] = true;
    parent[r] = 0; 

    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : adj[u]) {
            if (!vis[v]) {
                vis[v] = true;
                parent[v] = u;
                q.push(v);
            }
        }
    }
}


long long get_path_sum(int u) {
    long long s = 0;
    int cur = u;
    
    while (cur != 0) {
        s += vals[cur];
        cur = parent[cur];
    }
    return s;
}

void run_test_case() {
    
    n = inf.readInt(2, 1000, "n");
    
    
    long long local_limit = n + 200;
    query_limit += local_limit;
    
    
    log_metrics();

    
    adj.assign(n + 1, vector<int>());
    vector<pair<int, int>> edges_out;
    for (int i = 0; i < n - 1; ++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);
        edges_out.push_back({u, v});
    }

    
    root_node = inf.readInt(1, n, "root");
    vals.assign(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        vals[i] = inf.readInt(-1, 1, "val");
        
        if (vals[i] == 0) vals[i] = 1;
    }

    
    cout << n << endl;
    for (const auto& p : edges_out) {
        cout << p.first << " " << p.second << endl;
    }
    cout.flush(); 

    
    build_tree(root_node);

    
    int local_q = 0;
    while (true) {
        string token;
        if (!(cin >> token)) {
            finish(_wa, "Unexpected EOF (expected '?' or '!')");
        }

        if (token == "!") {
            
            vector<int> user_vals(n + 1);
            for (int i = 1; i <= n; ++i) {
                string vs;
                if (!(cin >> vs)) finish(_wa, "Unexpected EOF reading answer");
                try {
                    user_vals[i] = stoi(vs);
                } catch (...) {
                    finish(_wa, "Answer values must be integers");
                }
            }

            
            for (int i = 1; i <= n; ++i) {
                if (user_vals[i] != vals[i]) {
                    finish(_wa, format("Incorrect value for node %d. Expected %d, got %d", i, vals[i], user_vals[i]));
                }
            }
            
            return;
        } else {
            
            int type = -1;
            
            if (token == "?") {
                if (!(cin >> type)) finish(_wa, "Expected query type after '?'");
            } else {
                try {
                    type = stoi(token);
                } catch (...) {
                    finish(_wa, "Invalid query token (expected '?' or query type)");
                }
            }

            local_q++;
            queries++;

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

            
            if (queries > 200000) finish(_pe, "Hard query limit exceeded");

            
            if (local_q > local_limit) {
                finish(_wa, format("Query limit exceeded for this test case (%d > %lld)", local_q, local_limit));
            }

            if (type == 1) {
                
                int k;
                if (!(cin >> k)) finish(_wa, "Expected k for query type 1");
                if (k < 1 || k > n) finish(_wa, format("Invalid k=%d", k));

                long long total_sum = 0;
                for (int i = 0; i < k; ++i) {
                    int u;
                    if (!(cin >> u)) finish(_wa, "Expected node index");
                    if (u < 1 || u > n) finish(_wa, format("Invalid node index %d", u));
                    total_sum += get_path_sum(u);
                }

                cout << total_sum << endl;
                cout.flush(); 
            } else if (type == 2) {
                
                int u;
                if (!(cin >> u)) finish(_wa, "Expected node index for query type 2");
                if (u < 1 || u > n) finish(_wa, format("Invalid node index %d", u));
                
                
                vals[u] = -vals[u];
                
            } else {
                finish(_wa, format("Unknown query type %d", type));
            }
        }
    }
}

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

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

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

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


Adaptive interactor (C++):

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

using namespace std;

int main(int argc, char* argv[]) {
    
    registerGen(argc, argv, 1);
    
    
    string mode = opt<string>("mode", "non");
    
    
    long long seed_val = atoll(argv[1]);
    
    int n;
    if (seed_val == 1) {
        n = 2; 
    } else if (seed_val == 2) {
        n = 1000; 
    } else if (seed_val == 3) {
        n = 3; 
    } else {
        
        
        
        n = 2 + rnd.wnext(999, 10); 
    }

    
    cout << 1 << "\n";
    
    cout << n << "\n";
    
    
    
    
    vector<pair<int, int>> edges;
    edges.reserve(n - 1);
    for (int i = 2; i <= n; i++) {
        
        if (rnd.next(2)) {
            edges.push_back({1, i});
        } else {
            edges.push_back({i, 1});
        }
    }
    
    
    shuffle(edges.begin(), edges.end());
    
    
    for (const auto& p : edges) {
        cout << p.first << " " << p.second << "\n";
    }
    
    
    if (mode == "non") {
        
        int root = rnd.next(1, n);
        cout << root << "\n";
        
        
        vector<int> vals(n);
        int strategy = rnd.next(4);
        
        if (strategy == 0) {
            
            for (int& x : vals) x = rnd.next(2) ? 1 : -1;
        } else if (strategy == 1) {
            
            for (int& x : vals) x = (rnd.next(10) == 0) ? -1 : 1;
        } else if (strategy == 2) {
            
            for (int& x : vals) x = (rnd.next(10) == 0) ? 1 : -1;
        } else {
            
            vector<int> temp(n);
            for (int i = 0; i < n; i++) temp[i] = (i < n / 2) ? 1 : -1;
            shuffle(temp.begin(), temp.end());
            vals = temp;
        }
        
        
        for (int i = 0; i < n; i++) {
            cout << vals[i] << (i == n - 1 ? "" : " ");
        }
        cout << "\n";
    }
    
    return 0;
}