#P1987H. Fumo Temple
Fumo Temple
Description
This is an interactive problem.
You are given two positive integers and ().
The jury has hidden from you a rectangular matrix with rows and columns, where for all and . The jury has also selected a cell . Your goal is to find .
In one query, you give a cell , then the jury will reply with an integer.
- If , the jury will reply with .
- Else, let be the sum of over all and such that and . Then, the jury will reply with .
Find by making at most queries.
Note: the grader is not adaptive: and are fixed before any queries are made.
Each test contains multiple test cases. The first line of input contains a single integer () — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers and () — the numbers of rows and the number of columns of the hidden matrix respectively.
It is guaranteed that the sum of over all test cases does not exceed .
Interaction
The interaction for each test case begins by reading the integers and .
To make a query, output "? i j" () without quotes. Afterwards, you should read one single integer — the answer to your query.
If you receive the integer instead of an answer or a valid value of or , 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" () 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 () — the number of test cases.
The first line of each test case contains two integers and () — the sizes of the hidden matrix.
The second line of each test case contains two integers and () — the hidden cell.
Then lines follow. The -th of them contains the string of length , consisting only of the characters -, 0, and +. Here, if , if , and if .
The sum of over all test cases should not exceed .
As an example, the hack format for the example input is:
Input
Each test contains multiple test cases. The first line of input contains a single integer () — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers and () — the numbers of rows and the number of columns of the hidden matrix respectively.
It is guaranteed that the sum of over all test cases does not exceed .
Note
The hidden matrix in the first test case:
The hidden matrix in the second test case:
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.