Cross Coloring codeforces solution- There is a sheet of paper that can be represented with a grid of size n×mn×m — nn rows and mm columns of cells. All cells are colored in white initially.

Cross Coloring solution codeforces

There is a sheet of paper that can be represented with a grid of size n×mn×m — nn rows and mm columns of cells. All cells are colored in white initially.

qq operations have been applied to the sheet. The ii-th of them can be described as follows:

  • xixi yiyi — choose one of kk non-white colors and color the entire row xixi and the entire column yiyi in it. The new color is applied to each cell, regardless of whether the cell was colored before the operation.

The sheet after applying all qq operations is called a coloring. Two colorings are different if there exists at least one cell that is colored in different colors.

Cross Coloring solution codeforces

How many different colorings are there? Print the number modulo 998244353998244353.

Input

The first line contains a single integer tt (1t1041≤t≤104) — the number of testcases.

The first line of the testcase contains four integers n,m,kn,m,k and qq (1n,m,k,q21051≤n,m,k,q≤2⋅105) — the size of the sheet, the number of non-white colors and the number of operations.

The ii-th of the following qq lines contains a description of the ii-th operation — two integers xixi and yiyi (1xin1≤xi≤n1yim1≤yi≤m) — the row and the column the operation is applied to.

The sum of qq over all testcases doesn’t exceed 21052⋅105.

Output

For each testcase, print a single integer — the number of different colorings modulo 998244353998244353.

Example

input

Cross Coloring solution codeforces

Copy
2
1 1 3 2
1 1
1 1
2 2 2 3
2 1
1 1
2 2

output

Copy
3
4

For Solution

Click Here!

Leave a Comment

Your email address will not be published.