#P1987H. Fumo Temple

Fumo Temple

Description

This temple only magnifies the mountain's power.
Badeline

This is an interactive problem.

You are given two positive integers nn and mm (nm\bf{n \le m}).

The jury has hidden from you a rectangular matrix aa with nn rows and mm columns, where ai,j{1,0,1}a_{i,j} \in \{ -1, 0, 1 \} for all 1in1 \le i \le n and 1jm1 \le j \le m. The jury has also selected a cell (i0,j0)(i_0, j_0). Your goal is to find (i0,j0)(i_0,j_0).

In one query, you give a cell (i,j)(i, j), then the jury will reply with an integer.

  • If (i,j)=(i0,j0)(i, j) = (i_0, j_0), the jury will reply with 00.
  • Else, let SS be the sum of ax,ya_{x,y} over all xx and yy such that min(i,i0)xmax(i,i0)\min(i, i_0) \le x \le \max(i, i_0) and min(j,j0)ymax(j,j0)\min(j, j_0) \le y \le \max(j, j_0). Then, the jury will reply with ii0+jj0+S|i - i_0| + |j - j_0| + |S|.

Find (i0,j0)(i_0, j_0) by making at most n+225n + 225 queries.

Note: the grader is not adaptive: aa and (i0,j0)(i_0,j_0) are fixed before any queries are made.

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

The only line of each test case contains two integers nn and mm (1nm50001 \le n \le m \le 5000) — the numbers of rows and the number of columns of the hidden matrix aa respectively.

It is guaranteed that the sum of nmn \cdot m over all test cases does not exceed 2510625 \cdot 10^6.

Interaction

The interaction for each test case begins by reading the integers nn and mm.

To make a query, output "? i j" (1in,1jm1 \le i \le n, 1 \le j \le m) without quotes. Afterwards, you should read one single integer — the answer to your query.

If you receive the integer 1-1 instead of an answer or a valid value of nn or mm, 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 "! i j" (1in,1jm1 \le i \le n, 1 \le j \le m) without quotes — the indices of the hidden cell. After solving a test case, your program should move to the next one immediately. After solving all test cases, your program should be terminated immediately.

After printing a query do not forget to output 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 (1t501 \le t \le 50) — the number of test cases.

The first line of each test case contains two integers nn and mm (1nm50001 \le n \le m \le 5000) — the sizes of the hidden matrix.

The second line of each test case contains two integers i0i_0 and j0j_0 (1i0n,1j0m1 \le i_0 \le n, 1 \le j_0 \le m) — the hidden cell.

Then nn lines follow. The ii-th of them contains the string sis_i of length nn, consisting only of the characters -, 0, and +. Here, aij=1a_{ij} = -1 if sij=s_{ij} = \mathtt{-}, aij=0a_{ij} = 0 if sij=0s_{ij} = \mathtt{0}, and aij=1a_{ij} = 1 if sij=+s_{ij} = \mathtt{+}.

The sum of nmn \cdot m over all test cases should not exceed 2510625 \cdot 10^6.

As an example, the hack format for the example input is:

23414+0+0+00+0---11110\texttt{2}\\ \texttt{3}\,\texttt{4} \\ \texttt{1}\,\texttt{4} \\ \texttt{+0+0} \\ \texttt{+00+} \\ \texttt{0---} \\ \texttt{1}\,\texttt{1}\\\texttt{1}\,\texttt{1}\\\texttt{0}

Input

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

The only line of each test case contains two integers nn and mm (1nm50001 \le n \le m \le 5000) — the numbers of rows and the number of columns of the hidden matrix aa respectively.

It is guaranteed that the sum of nmn \cdot m over all test cases does not exceed 2510625 \cdot 10^6.

Sample Input 1

2
3 4

5

3

5

1 1

0

Sample Output 1

? 1 1

? 3 3

? 3 2

! 1 4

? 1 1

! 1 1

Note

The hidden matrix in the first test case:

1100110\color{red}{\textbf{0}}
11000011
001-11-11-1

The hidden matrix in the second test case:

0\color{red}{\textbf{0}}

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.