#3207. Master of GCD
Master of GCD
Problem Description
Hakase has numbers in a line. At first, they are all equal to . Besides, Hakase is interested in primes. She will choose a continuous subsequence and a prime parameter each time and for every , she will change into . To simplify the problem, will be or . After operations, Hakase wants to know what is the greatest common divisor of all the numbers.
Input
The first line contains an integer representing the number of test cases.
For each test case, the first line contains two integers and , where refers to the length of the whole sequence and means there are operations.
The following lines, each line contains three integers , which are referred above.
Output
For each test case, print an integer in one line, representing the greatest common divisor of the sequence. Due to the answer might be very large, print the answer modulo .
Sample
2
5 3
1 3 2
3 5 2
1 5 3
6 3
1 2 2
5 6 2
1 6 2
6
2
Hint
For the first test case, after all operations, the numbers will be . So the greatest common divisor is .