#P1614C. Divan and bitwise operations

    ID: 187 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>bitmaskscombinatoricsconstructive algorithmsdpmath*1500

Divan and bitwise operations

No submission language available for this problem.

Description

Once Divan analyzed a sequence a1,a2,,ana_1, a_2, \ldots, a_n consisting of nn non-negative integers as follows. He considered each non-empty subsequence of the sequence aa, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence aa.

A sequence cc is a subsequence of a sequence dd if cc can be obtained from dd by deletion of several (possibly, zero or all) elements. For example, [1,2,3,4][1, \, 2, \, 3, \, 4], [2,4][2, \, 4], and [2][2] are subsequences of [1,2,3,4][1, \, 2, \, 3, \, 4], but [4,3][4, \, 3] and [0][0] are not.

Divan was very proud of his analysis, but now he lost the sequence aa, and also the coziness value! However, Divan remembers the value of bitwise OR on mm contiguous subsegments of the sequence aa. It turns out that each element of the original sequence is contained in at least one of these mm segments.

Divan asks you to help find the coziness of the sequence aa using the information he remembers. If several coziness values are possible, print any.

As the result can be very large, print the value modulo 109+710^9 + 7.

The first line contains one integer number tt (1t1031 \le t \le 10^3) — the number of test cases.

The first line of each test case contains two integer numbers nn and mm (1n,m21051 \le n, m \le 2 \cdot 10^5) — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.

The following mm lines describe the segments, one per line.

Each segment is described with three integers ll, rr, and xx (1lrn1 \le l \le r \le n, 0x23010 \le x \le 2^{30} - 1) — the first and last elements of the segment and the bitwise OR of al,al+1,,ara_l, a_{l + 1}, \ldots, a_r, 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 nn and the sum of mm over all test cases do not exceed 21052 \cdot 10^5.

For each test case print the coziness any suitable sequence aa modulo 109+710^9 + 7.

Input

The first line contains one integer number tt (1t1031 \le t \le 10^3) — the number of test cases.

The first line of each test case contains two integer numbers nn and mm (1n,m21051 \le n, m \le 2 \cdot 10^5) — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.

The following mm lines describe the segments, one per line.

Each segment is described with three integers ll, rr, and xx (1lrn1 \le l \le r \le n, 0x23010 \le x \le 2^{30} - 1) — the first and last elements of the segment and the bitwise OR of al,al+1,,ara_l, a_{l + 1}, \ldots, a_r, 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 nn and the sum of mm over all test cases do not exceed 21052 \cdot 10^5.

Output

For each test case print the coziness any suitable sequence aa modulo 109+710^9 + 7.

Samples

Sample Input 1

3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2

Sample Output 1

4
20
112

Note

In first example, one of the sequences that fits the constraints is [0,2][0, 2]. Consider all its non-empty subsequences:

  • [0][0]: the bitwise XOR of this subsequence is 00;
  • [2][2]: the bitwise XOR of this subsequence is 22;
  • [0,2][0, 2]: the bitwise XOR of this subsequence is 22.

The sum of all results is 44, so it is the answer.

In second example, one of the sequences that fits the constraints is [0,5,5][0, \, 5, \, 5].

In third example, one of the sequences that fits the constraints is [5,6,7,0,2][5, \, 6, \, 7, \, 0, \, 2].