Bob has an empty number matrix with rows and
columns. The rows are numbered from
to
and the columns from
to
.
Bob plans to fill each cell in the matrix with an integer from to
(inclusive). However, there are
special constraints that Bob must follow. Each constraint is defined by five integers:
,
,
,
, and
. This means that in the submatrix with top-left corner
and bottom-right corner
, the maximum value among all the cells must be exactly
.
Bob wants to know how many valid ways there are to fill the entire matrix so that all constraints are satisfied. Since the answer may be very large, print the result modulo .
Input Specification
The first line of the input contains one integer (
), the number of test cases.
For each test case, the first line contains four integers ,
,
and
(
,
), the size of the number matrix, the value range of the numbers, and the number of special requirements.
Each of the following lines contains five integers
,
,
,
and
(
,
,
), indicating a special requirement that the maximal integer in the submatrix from
to
is
.
Output Specification
For each test case, print a single line — the number of valid ways to fill the matrix such that all constraints are satisfied, modulo .
Constraints
Subtask | Points | Additional constraints |
---|---|---|
No additional constraints |
Sample Input
2
3 3 2 2
1 1 2 2 2
2 2 3 3 1
4 4 4 4
1 1 2 3 3
2 3 4 4 2
2 1 4 3 2
1 2 3 4 4
Sample Output
28
76475
Comments