File size: 1,139 Bytes
0d1690e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Dimash learned that Mansur wrote something very unpleasant about him to a friend, so he decided to find out his password at all costs and discover what exactly he wrote.

Believing in the strength of his password, Mansur stated that his password — is a binary string of length $n$. He is also ready to answer Dimash's questions of the following type:

Dimash says a binary string $t$, and Mansur replies whether it is true that $t$ is a substring of his password.

Help Dimash find out the password in no more than $2n$ operations; otherwise, Mansur will understand the trick and stop communicating with him.

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.



In the first example, the string $010$ is given. Therefore, the answers to the queries are as follows:

"? 00" $00$ is not a substring of $010$, so the answer is $0$.

"? 000" $000$ is not a substring, so the answer is $0$.

"? 010" $010$ is a substring, so the answer is $1$.

In the second example, the string is $1100$, in the third $0110$, and in the fourth $10$.