#P7341. 『MdOI R4』Phoenix

『MdOI R4』Phoenix

Description

Given nn distinct sets s1sns_1 \dots s_n, where all numbers in the sets are integers within the range [1,m][1, m].

Now you need to find how many permutations pp of 1n1 \sim n satisfy

$$(\sum\limits_{i=1}^n |s_i|)-(\sum\limits_{i=1}^{n-1} |s_{p_i}\bigcap s_{p_{i+1}}|)=|\bigcup\limits_{i=1}^n s_i|$$

The answer should be taken modulo 998244353998244353. It is guaranteed that the real answer before taking modulo is greater than 00.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer TT indicating the number of test cases. For each test case:

The first line contains two positive integers n,mn, m.

The second line contains nn positive integers a1,a2,,ana_1, a_2, \cdots, a_n. Each positive integer represents a set under state compression. If the kk-th bit (from low to high) of aia_i in binary is 11, then sis_i contains kk; otherwise, sis_i does not contain kk.

Output Format

Output TT lines, each corresponding to one test case.

For each test case, output one integer per line indicating the answer.

1
3 3
1 3 7
4
2
5 9
2 30 98 386 482
4 2 
1 3 3 1
12
12

Hint

[Sample Explanation #1]

The three sets are {1},{1,2},{1,2,3}\{1\}, \{1,2\}, \{1,2,3\}.

There are 44 permutations that satisfy the condition: (1,2,3),(1,3,2),(2,3,1),(3,2,1)(1,2,3), (1,3,2), (2,3,1), (3,2,1).

[Constraints and Agreements]

This problem uses bundled testdata.

Subtask ID nn \le mm \le Special Property Score
11 1010 2020 No special restrictions 1010
22 3030 No special restrictions ai=2ia_i = 2^i
33 No special restrictions aioraj=max(ai,aj)a_i \operatorname{or} a_j = \max(a_i, a_j)
44 Each set contains exactly two elements 2020
55 2020 No special restrictions
66 No special restrictions 3030

For 100%100\% of the testdata, 1T501 \le T \le 50, 1n1051 \le \sum n \le 10^5, 1m601 \le m \le 60, 0ai2m10 \le a_i \le 2^m - 1, where n\sum n denotes the sum of nn over all test cases.

[Tips and Help]

The input size of this problem is large, so please choose a faster input method.

Thanks to JohnVictor\rm\textcolor{black}{J}\textcolor{red}{ohnVictor} for contributing to this problem.

Translated by ChatGPT 5