#SL2310G. Make 2
Make 2
Make 2
For a sequence consisting of positive integers, you can perform the following operation several times:
- Choose an index which satisfies and , then decrease by , and add to and .
A sequence consisting of positive integers is considered good if it is possible to make for each , by using several (possibly, zero) such operations.
Now you need to calculate the number of good sequences that satisfy constraints, the -th constraint can be represented as a pair which requires .
It can be proven that the answer is finite. Output the answer modulo .
Input
The first line contains a single integer , denoting the number of test cases.
For each test case, the first line contains two integers $n,m \: (1 \leq n \leq 10^{18}, 0 \leq m \leq min(n,100))$.
The next lines each contains two integers. The -th line contains $x_i,y_i \: (1 ≤ x_1 < x_2 < \dots < x_m \leq n, 1 \leq y_i \leq10^9)$.
Output
For each test case, output one line with an integer denoting the answer modulo .
Example
3
3 1
2 2
5 2
1 2
5 1
114514 0
1
2
158552999