#G. Problem G. Travel

    传统题 8000ms 512MiB

Problem G. Travel

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Description

Alice is currently traveling in a k-dimensional space. She starts at (0, 0, . . . , 0), and she has a total of n teleportation skills. When she uses a teleportation skill, if she is at (x1,x2,...,xkx_1, x_2, . . . , x_k) and the teleportation skill is (y1,y2,...,yky_1, y_2, . . . , y_k), she will be teleported to (x1+y1,...,xk+ykx_1 + y_1, . . . , x_k + y_k). Teleportation skills can be used in any way. This k-dimensional space is finite, and the size of the i-th dimension is Ni . In other words, for the i-th dimension, the coordinate range is 0xiNi0 ≤ x_i ≤ N_i . Alice’s destination is (N1,...,NkN_1, . . . , N_k). There are a total of m black holes in the k-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 T(1T51 ≤ T ≤ 5) — the number of test cases. Description of the test cases follows. The first line of each test case contains one integers k (2k62 ≤ k ≤ 6)—This means that the space has a total of kdimensions. The next line contains k positive integers Ni (1Ni1051 ≤ Ni ≤ 10^5 ), representing the size of the i-th dimension.The next line contains two integers n and m , (1n105,0m10001 ≤ n ≤ 10^5 , 0 ≤ m ≤ 1000) , representing the number of teleportation skills and the number of obstacles, respectively. The next n lines contain k non-negative integers (y1,...,yky_1, . . . , y_k), where (i[1,k],0yiNi∀i ∈ [1, k], 0 ≤ y_i ≤ N_i), representing the current teleportation skills. The next m lines contain k non-negative integers (x1,...,xkx_1, . . . , x_k), where (i[1,k],0xiNi∀i ∈ [1, k], 0 ≤ x_i ≤ N_i), representing the coordinates of the black holes. It is guaranteed that there is no leap skill corresponding to (0,0,,00, 0, · · · , 0. The data ensures that i=1k(Ni+1)2×105 \prod ^k _{i=1}(N_i + 1) ≤ 2 × 10^5 .

Output

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

Samples

1 
2 
100 1000 
2 0 
1 0 
0 1
555294450

Limitation

12s, 512mb for each test case.

杭电“钉耙编程”挑战(纯英纯硬,持续更新ing)

未参加
状态
已结束
规则
ACM/ICPC
题目
7
开始于
2023-8-5 12:00
结束于
2023-9-24 12:00
持续时间
1200 小时
主持人
参赛人数
28