Gyeonggeun invented a new computer. Unlike other computers, it stores data in base 4 instead of base 2.
On this computer the results of p+q and p⊕q are given by the tables below. The row is p and the column is q.
p+q
| + | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 |
| 1 | 1 | 2 | 3 | 0 |
| 2 | 2 | 3 | 0 | 1 |
| 3 | 3 | 0 | 1 | 2 |
p⊕q
| ⊕ | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 |
| 1 | 1 | 0 | 3 | 2 |
| 2 | 2 | 3 | 0 | 1 |
| 3 | 3 | 2 | 1 | 0 |
Gyeonggeun thought his invention was so innovative that he wanted to try it out at once, so he built the machine himself.
He put it together temporarily on a very small budget, so it stores only N variables, and each variable holds a single integer from 0 to 3. For convenience Gyeonggeun numbered the variables from 0 to N−1 and calls variable number i by the name vi.
Gyeonggeun took his time and made the four basic commands he judged necessary.
addv x y z (0≤x,y,z≤N−1, and x, y, z are all integers): assigns the value of vy+vz to vx.xorv x y z (0≤x,y,z≤N−1, and x, y, z are all integers): assigns the value of vy⊕vz to vx.addc x y z (0≤x,y≤N−1, 0≤z≤3, and x, y, z are all integers): assigns the value of vy+z to vx.xorc x y z (0≤x,y≤N−1, 0≤z≤3, and x, y, z are all integers): assigns the value of vy⊕z to vx.Gyeonggeun wrote code that lists M basic commands. Compiling the code produces a program. Before running any command, the program reads the value to store in each variable vi, executes the M commands of the code one at a time in order, and then prints the value held by each variable vi once all commands are done. For convenience, write the input as a0,a1,…,aN−1 and the output as b0,b1,…,bN−1.
Because of a mistake in Gyeonggeun's implementation, every variable vi has one value fi (0≤fi≤3) that cannot be stored in it at the start. So ai=fi must hold, and ai can be any of the three values among 0, 1, 2, 3 other than fi. There are therefore 3N possible inputs.
To learn whether he wrote the program correctly, Gyeonggeun decides to go through every possible input. He bought a notebook of N pages and numbered the pages from 0 to N−1. He builds every possible input, feeds each one to the program once, takes the output b0,b1,…,bN−1 for that input, and writes the value of bi on page i.
After every input has been gone through, let si be the sum of the numbers written on page i. Before starting the work, Gyeonggeun wants one minimal safeguard: the remainder of si divided by 4, for every i.
The first line contains the number of variables N (1≤N≤18) and the number of commands M (0≤M≤400).
The second line contains f0,f1,…,fN−1 (0≤fi≤3), separated by spaces. Here fi is the value that cannot be stored in variable vi before the commands run, and it is an integer.
Each of the next M lines contains one command, in the order the commands run. Line j (1≤j≤M) has one of the formats below. Every number given is an integer, and the numbers are separated by single spaces.
0 x y z (0≤x,y,z≤N−1): the jth command to run is addv x y z.1 x y z (0≤x,y,z≤N−1): the jth command to run is xorv x y z.2 x y z (0≤x,y≤N−1, 0≤z≤3): the jth command to run is addc x y z.3 x y z (0≤x,y≤N−1, 0≤z≤3): the jth command to run is xorc x y z.Let ti be the remainder of si divided by 4. Print t0,t1,…,tN−1 on the first line, separated by spaces.