E. Shiro's Mirror Duel
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There's no such thing as luck in this world. The victor is decided before the game even starts.
No Game No Life

This is an interactive problem.

One day, Sora and Shiro feel bored again, so they decide to settle it with a game.

At the beginning, Sora gives Shiro a permutation$$$^{\text{∗}}$$$ $$$p_1,p_2,\ldots,p_n$$$ of length $$$n$$$. In each operation, Shiro may select two distinct indices $$$x$$$ and $$$y$$$ ($$$1\le x\ne y\le n$$$). Then Sora flips a fair coin:

  • With probability $$$0.5$$$, Sora swaps $$$p_x$$$ and $$$p_y$$$;
  • With probability $$$0.5$$$, Sora swaps $$$p_{n-x+1}$$$ and $$$p_{n-y+1}$$$.

After the operation, Sora replies with the actual pair of indices that were swapped, so that Shiro can update her local permutation accordingly.

Shiro's goal is to sort the permutation $$$p$$$ in ascending order by using at most $$$\lfloor 2.5n+800\rfloor$$$ operations. Help her!

$$$^{\text{∗}}$$$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).

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 4000$$$) — the length of $$$p$$$.

The second line contains $$$n$$$ integers $$$p_1,p_2,\ldots,p_n$$$ — the elements of $$$p$$$.

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

It is guaranteed that there are $$$50$$$ tests in this problem.

Interaction

For each test case, you can use at most $$$\lfloor 2.5n+800\rfloor$$$ moves to sort the permutation $$$p$$$ in ascending order.

To make a move, you should print a new line in the following format:

  • $$$\mathtt{?}\; x\; y$$$ ($$$1 \le x \ne y \le n$$$) — the two indices that Shiro selects in this move.

As a response to the move, you will receive two integers $$$u$$$ and $$$v$$$ — the actual pair of indices that Sora swapped. It is guaranteed that $$$(u, v)$$$ is randomly selected from $$$(x, y)$$$ and $$$(n-x+1, n-y+1)$$$ with equal probability.

To report that the permutation has been sorted in ascending order, you should print a new line with a single character $$$\mathtt{!}$$$. This does not count as one of the $$$\lfloor 2.5n+800\rfloor$$$ moves.

After that, proceed to the next test case or terminate the program if it was the last test case.

After printing each query do not forget to output the end of line and flush$$$^{\text{∗}}$$$ the output. Otherwise, you will get Idleness limit exceeded verdict.

If, at any interaction step, you read $$$-1$$$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

Hacks are disabled in this problem.

$$$^{\text{∗}}$$$To flush, use:

  • fflush(stdout) or cout.flush() in C++;
  • sys.stdout.flush() in Python;
  • see the documentation for other languages.
Example
Input
2
5
5 1 3 4 2

1 5

2 1

2
1 2

Output



? 1 5

? 4 5

!


!
Note

In the first test case, $$$n=5$$$ and the initial permutation is $$$[5,1,3,4,2]$$$.

  • We print ? 1 5. The judge replies 1 5, meaning positions $$$1$$$ and $$$5$$$ are swapped (no mirroring). The array becomes $$$[2,1,3,4,5]$$$.
  • We print ? 4 5. The judge replies 2 1, which is the mirror of $$${4,5}$$$ because with $$$n=5$$$ we have $$$n-4+1=2$$$ and $$$n-5+1=1$$$. Thus we must swap positions $$$2$$$ and $$$1$$$. The array becomes $$$[1,2,3,4,5]$$$.
  • The permutation is now sorted, so we print !. The answer line does not count toward the operation limit.

In the second test case, the given permutation is already increasing, so we just need to output !.