#P9905. Make 2

Make 2

Make 2

Problem Description

For a sequence aa consisting of nn positive integers, you can perform the following operation several times:

  • Choose an index ii which satisfies 1<i<n1< i< n and ai>1a_i> 1, then decrease aia_i by 11, and add 11 to ai1a_{i-1} and ai+1a_{i+1}. A sequence consisting of nn positive integers is considered good if it is possible to make ai=2a_i=2 for each 1in1\leq i\leq n, by using several (possibly, zero) such operations. Now you need to calculate the number of good sequences that satisfy mm constraints, the ii-th constraint can be represented as a pair (xi,yi)(x_i, y_i) which requires axi=yia_{x_i}=y_i. It can be proven that the answer is finite. Output the answer modulo 109+710^9+7.

Input

The first line contains a single integer TT (1T101\le T\le 10), denoting the number of test cases. For each test case, the first line contains two integers n,mn,m (1n10181\le n\le 10^{18}, 0mmin(n,100)0\le m\le \min(n,100)). The next mm lines each contains two integers. The ii-th line contains xi,yix_i,y_i (1x1<x2<<xmn1\le x_1< x_2< \cdots < x_m\le n, 1yi1091\le y_i\le 10^9).

Output

For each test case, output one line with an integer denoting the answer modulo 109+710^9+7.

Sample Input

3
3 1
2 2
5 2
1 2
5 1
114514 0

Sample Output

1
2
158552999

Source

2023“钉耙编程”中国大学生算法设计超级联赛(10)