#P1977E. Tensor

    ID: 9272 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>constructive algorithmsgraphsinteractive*2600

Tensor

No submission language available for this problem.

Description

This is an interactive problem.

You are given an integer nn.

The jury has hidden from you a directed graph with nn vertices (numbered from 11 to nn) and some number of edges. You additionally know that:

  • The graph only contains edges of the form iji \leftarrow j, where 1i<jn1 \le i < j \le n.
  • For any three vertices 1i<j<kn1 \le i < j < k \le n, at least one of the following holds^\dagger:
    • Vertex ii is reachable from vertex jj, or
    • Vertex ii is reachable from vertex kk, or
    • Vertex jj is reachable from vertex kk.

You want to color each vertex in either black or white such that for any two vertices ii and jj (1i<jn1 \le i < j \le n) of the same color, vertex ii is reachable from vertex jj.

To do that, you can ask queries of the following type:

  • ? i j — is vertex ii reachable from vertex jj (1i<jn1 \le i < j \le n)?

Find any valid vertex coloring of the hidden graph in at most 2n2 \cdot n queries. It can be proven that such a coloring always exists.

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

^\dagger Vertex aa is reachable from vertex bb if there exists a path from vertex bb to vertex aa in the graph.

Each test contains multiple test cases. The first line of input contains a single integer tt (1t10001 \le t \le 1000) — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single integer nn (3n1003 \le n \le 100) — the number of vertices in the hidden graph.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000.

Interaction

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

To make a query, output "? i j" without quotes (1i<jn1 \le i < j \le n). If vertex ii is reachable from vertex jj, you will get YES as an answer. Otherwise, you will get NO as an answer.

If you receive the integer 1-1 instead of an answer or a valid value of nn, it means your program has made an invalid query, has exceeded 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 "! c1 c2  cnc_1 \ c_2 \ \ldots \ c_n" without quotes — the colors of the vertices, where ci=0c_i = 0 if the vertex is black, and ci=1c_i = 1 if the vertex is white. After solving all test cases, your program should be terminated immediately.

After printing a query, do not forget to output an 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.

Hacks

To hack, use the following format:

The first line contains an integer tt (1t10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains two integers nn and mm (3n1003 \le n \le 100, 0mn(n1)20 \le m \le \frac{n\cdot(n - 1)}{2}) — the number of vertices and edges in the graph.

Each of the following mm lines should contain two integers aa and bb (1b<an1 \le b < a \le n), indicating that there is the edge aba \rightarrow b in the graph. The graph should satisfy the conditions above.

The sum of nn over all test cases should not exceed 10001000.

Input

Each test contains multiple test cases. The first line of input contains a single integer tt (1t10001 \le t \le 1000) — the number of test cases. The description of the test cases follows.

The only line of each test case contains a single integer nn (3n1003 \le n \le 100) — the number of vertices in the hidden graph.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000.

Sample Input 1

2
4

YES

YES

YES

NO

NO

NO

5

Sample Output 1

? 1 2

? 2 3

? 1 3

? 1 4

? 2 4

? 3 4

! 0 0 0 1

! 1 1 0 1 0

Note

The hidden graph in the first test case:

The hidden graph in the second test case:

The interaction happens as follows:

SolutionJuryExplanation
2There are 22 test cases.
4In the first test case, the graph has 44 vertices.
? 1 2 YESThe solution asks if vertex 11 is reachable from vertex 22, and the jury answers YES.
? 2 3 YESThe solution asks if vertex 22 is reachable from vertex 33, and the jury answers YES.
? 1 3 YESThe solution asks if vertex 11 is reachable from vertex 33, and the jury answers YES.
? 1 4 NOThe solution asks if vertex 11 is reachable from vertex 44, and the jury answers NO.
? 2 4 NOThe solution asks if vertex 22 is reachable from vertex 44, and the jury answers NO.
? 3 4 NOThe solution asks if vertex 33 is reachable from vertex 44, and the jury answers NO.
! 0 0 0 1The solution has somehow determined a valid coloring and outputs it. Since the output is correct, the jury continues to the next test case.
5In the second test case, the graph has 55 vertices.
! 1 1 0 1 0The solution has somehow determined a valid coloring, 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.