问题 G: Make 2

内存限制:512 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

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

  • Choose an index i which satisfies 1<�<�1<i<n and ��>1ai>1, then decrease ��ai by 11, and add 11 to ��−1ai1 and ��+1ai+1.

A sequence consisting of n positive integers is considered good if it is possible to make ��=2ai=2 for each 1≤�≤�1in, by using several (possibly, zero) such operations.

Now you need to calculate the number of good sequences that satisfy m constraints, the i-th constraint can be represented as a pair (��,��)(xi,yi) which requires ���=��axi=yi.

It can be proven that the answer is finite. Output the answer modulo 109+7109+7.

输入格式

The first line contains a single integer T (1≤�≤101T10), denoting the number of test cases.

For each test case, the first line contains two integers �,�n,m (1≤�≤10181n10180≤�≤min⁡(�,100)0mmin(n,100)).

The next m lines each contains two integers. The i-th line contains ��,��xi,yi (1≤�1<�2<⋯<��≤�1x1<x2<<xmn1≤��≤1091yi109).

输出格式

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

输入样例 复制

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

输出样例 复制

1
2
158552999