#1421. Travel

Travel

Alice is currently traveling in a kk-dimensional space. She starts at (0,0,...,0)(0, 0, . . . , 0), and she has a total of nn teleportation skills. When she uses a teleportation skill, if she is at (x1,x2,...,xk)(x_1, x_2, . . . , x_k) and the teleportation skill is (y1,y2,...,yk)(y_1, y_2, . . . , y_k), she will be teleported to (x1+y1,...,xk+yk)(x_1 + y_1, . . . , x_k + y_k). Teleportation skills can be used in any way.

This kk-dimensional space is finite, and the size of the ii-th dimension is NiN_i. In other words, for the ii-th dimension, the coordinate range is 0xiNi0 \le x_i \le N_i.

Alice’s destination is (N1,...,Nk)(N_1, . . . , N_k). There are a total of mm black holes in the kk-dimensional space, which means Alice cannot reach those positions in any way. Alice wants to know how many ways she can use teleportation skills to reach her destination without passing through any black holes.

We consider two different teleportation plans to be different if and only if there exists a step where the two plans use different teleportation skills.

Two teleportation skills are considered different if and only if their skill numbers are different. Even if the effects of these two skills are exactly the same, they will still be considered as two separate skills.

Since the answer can be large, please output it modulo 998244353.

Input

The input consists of multiple test cases. The first line contains a single integer TT(1T51 \le T \le 5) — the number of test cases. Description of the test cases follows.

The first line of each test case contains one integers kk (2k62 \le k \le 6) — This means that the space has a total of kk dimensions.

The next line contains kk positive integers NiN_i (1Ni1051 \le N_i \le 10^5), representing the size of the ii-th dimension.

The next line contains two integers nn and mm, (1n1051 \le n \le 10^5, 0m10000 \le m \le 1000), representing the number of teleportation skills and the number of obstacles, respectively.

The next nn lines contain kk non-negative integers (y1,...,yk)(y_1, . . . , y_k), where (i[1,k] \forall i \in [1, k], 0yiNi0 \le y_i \le N_i), representing the current teleportation skills.

The next mm lines contain kk non-negative integers (x1,...,xk)(x_1, . . . , x_k), where (i[1,k] \forall i \in [1, k], 0xiNi0 \le x_i \le N_i), representing the coordinates of the black holes.

It is guaranteed that there is no leap skill corresponding to (0,0,,0)(0, 0, · · · , 0).

The data ensures that i=1k(Ni+1)2105\prod^k_{i=1}(Ni + 1) \le 2 \cdot 10^5.

Output

For each test case, output an integer representing the number of ways Alice can reach her destination modulo 998244353.

Example

1
2
100 1000
2 0
1 0
0 1
555294450

Limitation

Time limit: 12 seconds

Memory limit: 512 megabytes