#6416. [ICPC 2024 Hangzhou R] Japanese Bands

[ICPC 2024 Hangzhou R] Japanese Bands

[ICPC 2024 Hangzhou R] Japanese Bands

题目描述

Grammy is designing a new trading card game (TCG) based on her favorite Japanese music media franchise, $\textit{BanG Dream!}$. By her design, there are $n_1$ character cards and $n_2$ music cards in total. Now she needs to assign an integer between $1$ and $m$ (both inclusive) for each card, representing the magic power it contains.

In every TCG game, there must be some certain combos that may cause extra damage. Grammy now is considering a special rule that relates to the value assigned to cards. Specifically, kk pairs of integers (a1,b1),(a2,b2),⋯ ,(ak,bk)(a_1, b_1), (a_2, b_2), \cdots, (a_k, b_k) are chosen, satisfying 1≤ai,bi≤m1 \le a_i, b_i \le m. Grammy wants to make sure each of these value combos can be played in her game. Therefore, for each pair of integers (ai,bi)(a_i, b_i), the assignment must meet at least one of the two following constraints:

  • aia_i can be found on a character card and bib_i can be found on a music card.
  • aia_i can be found on a music card and bib_i can be found on a character card.

Please help Grammy count the number of valid card-value assignments.

Let C\mathbb{C} be the multi-set of the integers on the character card and M\mathbb{M} be the multi-set of the integers on the music card. We say two assignments are different if their C\mathbb{C}s are different or their M\mathbb{M}s are different.

Recall that an integer can appear multiple times in a multi-set. We say two multi-sets X\mathbb{X} and Y\mathbb{Y} are different if there exists an integer kk such that the number of times kk appears in X\mathbb{X} is not equal to that in Y\mathbb{Y}.

输入格式

There are multiple test cases. The first line of the input contains an integer $T$ ($1 \le T \le 500$) indicating the number of test cases. For each test case:

The first line contains four integers n1n_1, n2n_2, mm and kk (1≤n1,n2≤1091 \le n_1, n_2 \le 10^9, 1≤m≤201 \le m \le 20, 1≤k≤m21 \le k \le m^2).

For the following kk lines, the ii-th line contains two integers aia_i and bib_i (1≤ai,bi≤m1 \le a_i, b_i \le m).

It's guaranteed that there are at most 55 test cases satisfying m>10m > 10.

输出格式

For each test case output one line containing one integer indicating the number of valid card-value assignments. As the answer may be large, output the answer modulo $(10^9 + 7)$.
3
2 3 3 3
2 3
1 1
2 3
2 2 2 1
1 1
1 1 10 2
1 2
1 3
6
4
0

提示

For the first sample test case, the valid pairs of $(\mathbb{C}, \mathbb{M})$ are $(\{1, 2\}, \{1, 1, 3\})$, $(\{1, 2\}, \{1, 2, 3\})$, $(\{1, 2\}, \{1, 3, 3\})$, $(\{1, 3\}, \{1, 1, 2\})$, $(\{1, 3\}, \{1, 2, 2\})$ and $(\{1, 3\}, \{1, 2, 3\})$.

For the second sample test case, the valid pairs of (C,M)(\mathbb{C}, \mathbb{M}) are ({1,1},{1,1})(\{1, 1\}, \{1, 1\}), ({1,2},{1,1})(\{1, 2\}, \{1, 1\}), ({1,1},{1,2})(\{1, 1\}, \{1, 2\}) and ({1,2},{1,2})(\{1, 2\}, \{1, 2\}). 标签: P14196|2024|ICPC|杭州

来源

P14196|[ICPC 2024 Hangzhou R] Japanese Bands