Special Matrix
Submissions: 6740   Accuracy:


  Difficulty: Medium   Marks: 4

You are given a matrix having N rows and M columns. The special property of this matrix is that some of the cells of this matrix are blocked
i.e. they cannot be reached. Now you have to start from the cell (1,1) and reach the end (N,M) provided during the journey you can move horizontally right from the current cell or vertically down from the current cell.
Can you answer the number of ways you can traverse the matrix obeying the above constraints starting from (1,1) and ending at (N,M).

Output your answer modulo 10^9+7.

Input :
The first line contains T, the number of test cases. Then T test cases follow.
Each test case consists of two lines.
The first line contains  three integers N,M and K denoting the number of rows, the number of columns and the number of blocked cells in the matrix respectively. The next line contains space separated 2*K integers denoting the positions of the blocked cells in the form R1 C1 R2 C2 R3 C3…..RK CK.


Output :
For each test case output the the number of ways modulo 10^9+7 in a new line.


Constraints :
It is guaranteed that the cell (1,1) will never be blocked.


3 3 2
1 2 3 2

Output :   


Explanation :
For the above test case there is only one path from (1,1) to(3,3) which is

** For More Input/Output Examples Use 'Expected Output' option **

Author: Arnab Deb

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.