You have to color an M x N two dimensional grid. You will be provided K different colors for this. You will also be provided a list of B blocked cells of this grid. You cannot color these blocked cells.
A cell can be described as (x, y), which points to the yth cell from the left of the xth row from the top.
While coloring the grid, you have to follow these rules:
- You have to color each cell which is not blocked.
- You cannot color a blocked cell.
- You can choose exactly one color from K given colors to color a cell.
- No two vertically adjacent cells can have the same color, i.e. cell (x, y) and cell (x + 1, y) shouldn't contain the same color.
You have to calculate the numbe of ways you can color this grid obeying all the rules provided.
Input
Input starts with an integer T (≤ 600), denoting the number of test cases.
Each test case starts with a line containing four integers M N K B (1 ≤ M, N, K ≤ 106, 0 ≤ B ≤ 500). Each of the next B lines will contain two integers x and y (1 ≤ x ≤ M, 1 ≤ y ≤ N), the row and column number of a blocked cell. Each of these B lines will contain distinct cells.
Output
For each case, print the case number and the number of ways to color the grid modulo 109.
Sample
Sample Input | Sample Output |
---|---|
3 3 3 3 0 3 4 4 2 3 1 3 3 2 2 5 2 1 2 2 2 | Case 1: 1728 Case 2: 186624 Case 3: 20 |