G10_11 - Monkyes

no tags 

Peter has a rectangular table consisting of N rows and M columns. Rows are numbered by integers from 1 to N from top to bottom and columns are numbered from 1 to M from left to right. Let (x, y) denote the cell corresponding to xth row and yth column.

Peter has two monkeys, both initially at the cell (1, 1). He wants them to get to the cell (NM). Each of the monkey can move from some cell (xy) to cell (x+1, y) or cell (xy+1). As monkeys do not really like each other, they do not want to meet along their ways, except at the start (1,1) and end (NM) cells.

Also, there are exactly C cells in the table containing a banana. When a monkey goes through such a cell, he eats this banana. As Peter also wants to eat bananas, he wants that both the monkeys cumulatively don't eat more than D bananas.

Find out number of ways in which monkeys can get from cell (1, 1) to cell (NM) satisfying the above conditions. As answer could be large, please output your answer modulo MOD.

Input

  • The first line of the input contains an integer T denoting the number of test cases. The description of test cases follows.
  • The first line of each test case contains five space-separated integers NMCD and MOD denoting the sizes of table, the number of cells with a banana, the maximum number of bananas that can be eaten by monkeys and the modulo.
  • Each of next C lines contains two space-separated integers xi and yi denoting the coordinates of the cell with a banana.

Output

  • For each test case, output a single line containing the numbers of ways monkeys can get from cell (1, 1) to cell (NM) modulo MOD.

Constraints

  • 2 ≤ N, M ≤ 105
  • 0 ≤ D ≤ C ≤ min{200, N * M - 2}
  • 1 ≤ xi ≤ N
  • 1 ≤ yi ≤ M
  • 1 ≤ MOD ≤ 109
  • It's guaranteed that there is no banana in cells (1, 1) and (N, M)

Example

Input:
4
2 3 0 0 10
2 3 1 0 16
2 1
3 3 1 0 7
2 2
2 2 2 1 11
1 2
2 1

Output:
1
0
1
0


Added by:MaratónAFDM
Date:2018-07-25
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C NCSHARP CSHARP JAVA JULIA PYTHON PYPY3 PYTHON3