#P7818. Function

Function

Function

Problem Description

Given a sequence of length nn a[1..n]a[1..n], S(a)S(a) is a set generated by aa:

  1. S(a)={aii[1,n]}S(a)=\{a_i|i\in [1,n]\}, initially.
  2. If x,yS(a)x,y \in S(a) and xySx \oplus y \notin S, add xyx \oplus y to SS. Note that here \oplus denotes the bitwise exclusive or, i.e. , xorxor. If you knew little about that, please refer to https://en.wikipedia.org/wiki/Exclusive. Construct a mapping f:S(a)S(a)f:S(a) \rightarrow S(a) that satisfies all the following conditions:
  3. If xS(a)x \in S(a) satisfying f(x)=0f(x)=0, then yS(a)\exists y \in S(a), satisfying f(y)=xf(y)=x.
  4. If x,yS(a)x,y \in S(a) satisfying f(x)=yf(x)=y, then f(y)=0f(y)=0.
  5. $\forall x,y \in S(a), \ f(x\oplus y)=f(x) \oplus f(y)$. This problem contains two modes, specified by a parameter opop. The first mode: The parameter op=constructop=construct, it means that you are a contestant and you need to construct a solution, which will be checked by special judgespecial \ judge on the evaluation machine. Firstly, print NoSolutionNoSolution if there doesn't exist a mapping function ff on S(a)S(a) satisfying the above conditions and go on next test case( but you should also read some following extra data and do not print anything, see input ), otherwise print HaveSolutionHaveSolution representing that you have a solution. To check whether your solution is correct, then you are given an integer mm denoting the number of queries you should answer. For ii-th query, read a nonnegative integer xix_i, print f(xi)f(x_i) if xiS(a)x_i \in S(a) or 1-1 if xiS(a)x_i \notin S(a). If there exists a solution gg satisfying g(xi)=f(xi),i[1,m]g(x_i)=f(x_i),i\in [1,m], your solution will be assumed to be correct, otherwise it is wrong. The second mode: The parameter op=checkop=check, it means that you are the evaluation machine and you need to check a solution. Firstly, read a string stst, st=HaveSolutionst=HaveSolution or st=NoSolutionst=NoSolution denoting whether the evaluation machine assumes that there is a solution. If the conclusion is wrong, print NoNo and go on next test case(\textbf{but maybe you should also read some following extra data and do not print anything, see input}). Otherwise, if st=HaveSolutionst=HaveSolution, you should check whether the construction ff is correct. You are given an integer mm and mm pieces of information. For one of them, you should read a nonnegative integer xix_i, and f(xi)f(x_i) is either a nonnegative integer or 1-1 according to whether the evaluation machine assumes that xiS(a)x_i \in S(a). 1-1 means that it assumes that xiS(a)x_i \notin S(a). And you should also check that 1-1 is correct or not. Namely, you have to note that if the given xiS(a)x_i \notin S(a), but f(xi)1f(x_i) \ne -1, it is a wrong construction. Note that the solution given by the evaluation machine may be not generated randomly. If there exists a solution gg satisfying g(xi)=f(xi),i[1,m]g(x_i)=f(x_i),i\in [1,m], you should print YesYes denoting that the solution is correct, otherwise it is wrong and you should print NoNo. That is to say, the criterion is the same for the two modes. See the example for details.

Input

The first line contains one integer TT, T[1,550]T \in [1,550]. For each test case: The first line contains one integer nn, n[1,106]n \in [1,10^6]. The second line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n, ai[0,260)a_i \in [0,2^{60}). Then you should read a string opop. If op=contructop=contruct, next line contains one integer mm. The ii-th of the next mm lines contains one integer xix_i, xi[0,260)x_i \in [0,2^{60}). If op=checkop=check, then next line contains a string stst, st=HaveSolutionst=HaveSolution or st=NoSolutionst=NoSolution. If st=HaveSolutionst=HaveSolution, the next line contains one integer mm. Each of the next mm lines contains 22 integers xix_i and f(xi)f(x_i), xi[0,260),f(xi)[1,260)x_i \in [0,2^{60}),f(x_i) \in [-1,2^{60}). The total of nn does not exceed 2×1062 \times 10^6. The total of mm does not exceed 2×1052 \times 10^5.

Output

For each test case: If op=constructop=construct, print HaveSolutionHaveSolution if you have a solution and for each xix_i, output a line containing f(xi)f(x_i), or print NoSolutionNoSolution with no extra output if you assumes that there doesn't exist a solution. If op=checkop=check, output a line containing YesYes if it is correct, otherwise print NoNo.

Sample Input

4
4
1 1 2 3
check
HaveSolution
4
1 0
2 1
3 1
4 -1
1
1
construct
1
1
3
1 2 3
check
HaveSolution
2
1 0
4 1
3
1 2 3
construct
2
1
4

Sample Output

Yes
NoSolution
No
HaveSolution
3
-1

Source

2020 Multi-University Training Contest 5