Vanya loves all numbers divisible by the number M. Now, given 2 numbers N and M, she gives you the following task : Given 2 numbers N and M, you need to count the number of numbers consisting of N digits that have value greater than 0 and are divisible by M. All numbers should be valid numbers, and should not contain any leading zeros.
In retrospect, Vanya realized that this task might be just too easy for you, and adds the following constraint : She gives you X pairs of numbers, each pair consists of 2 numbers from 1 to 9. Given these pairs , assume one of them to be consisting of numbers a and b, you need to eliminate out all numbers in which a and b appear adjacent to each other.They should not be adjacent in any order, i.e a,b (in that order) as well as b,a (in that order) are not valid. After this elmination process, you need to report the number of valid numbers.
As the answer could be rather large, print it Modulo 109+7.
Input Format :
The first line of the input consists of a single integer T, denoting the number of test cases. The description of each test case is spread out as follows :
The first line of each test case consists of 3 integers N, M and X. Each of the next X lines contains 2 integers a and b, denoting the numbers a and b should not appear adjacent to each other in any of the valid numbers. It is guaranteed that there shall be no 2 pairs, where ai=aj and bi=bj.
Output Format :
For each test case, print the answer on a new line. As the answer can be rather large, print it Modulo 109+7.
Constraints :
1≤T≤10
1≤N≤103
1≤M≤100
1≤X≤81
1≤ai,bi≤9
In the first test case of the sample, you need to find the number of numbers that are of length 1, that are divisible by 3 and 1 and 8 do not appear adjacent to each other. There are 3 such numbers, 3, 6 and 9.