#P1614C. Divan and bitwise operations
Divan and bitwise operations
No submission language available for this problem.
Description
Once Divan analyzed a sequence consisting of non-negative integers as follows. He considered each non-empty subsequence of the sequence , computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence .
A sequence is a subsequence of a sequence if can be obtained from by deletion of several (possibly, zero or all) elements. For example, , , and are subsequences of , but and are not.
Divan was very proud of his analysis, but now he lost the sequence , and also the coziness value! However, Divan remembers the value of bitwise OR on contiguous subsegments of the sequence . It turns out that each element of the original sequence is contained in at least one of these segments.
Divan asks you to help find the coziness of the sequence using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo .
The first line contains one integer number () — the number of test cases.
The first line of each test case contains two integer numbers and () — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following lines describe the segments, one per line.
Each segment is described with three integers , , and (, ) — the first and last elements of the segment and the bitwise OR of , respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of and the sum of over all test cases do not exceed .
For each test case print the coziness any suitable sequence modulo .
Input
The first line contains one integer number () — the number of test cases.
The first line of each test case contains two integer numbers and () — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following lines describe the segments, one per line.
Each segment is described with three integers , , and (, ) — the first and last elements of the segment and the bitwise OR of , respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of and the sum of over all test cases do not exceed .
Output
For each test case print the coziness any suitable sequence modulo .
Samples
Note
In first example, one of the sequences that fits the constraints is . Consider all its non-empty subsequences:
- : the bitwise XOR of this subsequence is ;
- : the bitwise XOR of this subsequence is ;
- : the bitwise XOR of this subsequence is .
The sum of all results is , so it is the answer.
In second example, one of the sequences that fits the constraints is .
In third example, one of the sequences that fits the constraints is .