There is a growing tree, which has only one node on Day . This node is the root of the tree, numbered
and colored
.
For each type-2 event, output the answer. Please note that the input is encoded.
The first line of the input contains an integer, representing the number of test cases.
The first line of each test case contains two integers, representing the color of node
and the number of events.
Each of the followinglines of each test case contains three integers
, which has been encoded. You should decode it to get real input
with equations:
,
,
, where
is the answer of the last type-2 event or
if there is no type-2 event before in this test case,
is the number of nodes of the tree at the end of the previous day, and
is bitwise-xor operation.
It is guaranteed that the sum of
over all test cases does not exceed
.
For each type-2 event, output the answer in a single line.