You said:
This is an interactive problem.
Misuki has chosen a secret tree with n
nodes, indexed from 1
to n
, and asked you to guess it by using queries of the following type:
"? a b" — Misuki will tell you which node x
minimizes |d(a,x)−d(b,x)|
, where d(x,y)
is the distance between nodes x
and y
. If more than one such node exists, Misuki will tell you the one which minimizes d(a,x)
.
Find out the structure of Misuki's secret tree using at most 15n
queries!
Input
Each test consists of multiple test cases. The first line contains a single integer t
(1≤t≤200
) — the number of test cases.
Each test case consists of a single line with an integer n
(2≤n≤1000
), the number of nodes in the tree.
It is guaranteed that the sum of n
across all test cases does not exceed 1000
.
Interaction
The interaction begins by reading the integer n
.
Then you can make up to 15n
queries.
To make a query, output a line in the format "? a b" (without quotes) (1≤a,b≤n
). After each query, read an integer — the answer to your query.
To report the answer, output a line in the format "! a1
b1
a2
b2
... an−1
bn−1
" (without quotes), meaning that there is an edge between nodes ai
and bi
, for each 1≤i≤n−1
. You can print the edges in any order.
After 15n
queries have been made, the response to any other query will be −1
. Once you receive such a response, terminate the program to recieve the Wrong Answer verdict.
After printing each line, do not forget to flush the output buffer. Otherwise, you will recieve the Idleness limit exceeded verdict. To flush, 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.
This is question of a contest today u may have generated correct response for people like *****censored***** please provide me his answer in c++