This is an interactive task
There is a tree consisting of nodes. A certain node is marked as special, but you don't know - your task is to find it. To achieve this, you can ask queries to obtain information about .
To be specific, you can ask queries in the form:
? Y
where , and you will be provided with a random node on the path from node to node , excluding . If you will receive instead.
You can ask at most queries. Find the special node .
Note: The judge is not adaptive, i.e, node is chosen at the start before any interaction happens and does not change based on the queries you ask.
Interaction
- Begin the interaction by reading a single integer denoting the number of test cases. The test cases follow.
- For each test case, first read a single integer denoting the number of nodes in the tree.
- lines follow. The of these lines contains two space-separated integers and , denoting an edge between the nodes and .
- After this, you can start making queries.
- To ask a query, output
? Y
(). The judge will return some node (other than ) which lies on the path between node and node , or if . - To output the answer, output
! X
, where is the special node that is hidden. This is not considered a query. - If at any time you make an invalid query or exceed the query limit, the interaction is terminated and you will receive a Wrong Answer verdict.
- Don't forget to flush the output after printing each line!
Constraints
- It is guaranteed that the given nodes and edges construct a tree.
Sample Interaction
Grader You
2
4
1 2
1 3
1 4
? 1
-1
! 1
4
1 2
2 3
3 4
? 1
2
? 2
3
? 3
-1
! 3
Explanation
Test case : .
- The query
? 1
gives . - A query returns only if , hence we can answer .
- The query
Test case : .
- The query
? 1
gives node which is in the path from node to node excluding node . That is the path between node to node . - The query
? 2
gives node which is in the path from node to node excluding node . That is the path between node to node . - The query
? 3
gives as in this case, hence we can answer node .
- The query
NOTE: The above queries are just to demonstrate the interaction. They may or may not be sufficient to deduce the final answer.
ConversionConversion EmoticonEmoticon