Codeforces Round 992 (Div. 2)
F
Number of Cubes
Codeforces
2700
原题
← E→
翻译中…

Consider a rectangular parallelepiped with sides $a$, $b$, and $c$, that consists of unit cubes of $k$ different colors. We can apply cyclic shifts to the parallelepiped in any of the three directions any number of times$^{\text{∗}}$.

翻译中…

There are $d_i$ cubes of the $i$-th color ($1 \le i \le k$). How many different parallelepipeds (with the given sides) can be formed from these cubes, no two of which can be made equal by some combination of cyclic shifts?

翻译中…

$^{\text{∗}}$On the image: Top left shows the top view of the original parallelepiped. Lower layers will shift in the same way as the top layer. Top right shows the top view of a parallelepiped shifted to the right by $1$. Bottom left shows the top view of a parallelepiped shifted down by $2$. Bottom right shows the top view of a parallelepiped shifted to the right by $1$ and down by $2$. image

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

翻译中…

The first line of each test case contains four integers: $a$, $b$, $c$, and $k$ ($1 \le a, b, c \le 3 \cdot 10^6$; $a \cdot b \cdot c \le 3 \cdot 10^6$; $1 \le k \le 10^6$) — three sides of the parallelepiped and the number of colors of unit cubes.

翻译中…

The second line of each test case contains $k$ integers $d_1, d_2, \ldots, d_k$ ($1 \le d_1 \le d_2 \le \ldots \le d_k \le 3 \cdot 10^6$) — the elements of the array $d$: the number of cubes of a given color.

翻译中…

It is guaranteed that in each test case the sum of the elements of the array $d$ is equal to $a \cdot b \cdot c$.

翻译中…

It is guaranteed that the sum of $k$ over all test cases does not exceed $10 ^ 6$.

翻译中…

Output

翻译中…

For each test case, print one integer — the number of different parallelepipeds modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, there is only one parallelepiped, which consists of one unit cube.

翻译中…

Possible parallelepipeds in the second test case image

翻译中…

样例

Input #1
6
1 1 1 1
1
6 1 1 3
1 2 3
12 1 1 3
2 4 6
3 3 1 2
3 6
2 3 3 2
6 12
72 60 96 4
17280 86400 120960 190080
Output #1
1
10
1160
12
1044
231490207
InputCopy OutputCopy
题目信息
题号
2040F
时间限制
5 s
内存限制
256 MB
标签
组合数学
动态规划
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。