QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#15432. Bipartite Graph Matching Problem

통계

You are given a bipartite graph. The left part contains $n_1$ vertices numbered from 1 to $n_1$, and the right part contains $n_2$ vertices numbered from 1 to $n_2$. There are $m$ edges, each connecting one vertex on the left to one vertex on the right.

For every interval $[l, r]$ on the right side (where $1 \le l \le r \le n_2$), consider the subgraph obtained by:

  • keeping all left vertices $1, 2, \dots, n_1$;
  • keeping only the right vertices with indices in $[l, r]$;
  • keeping only edges whose endpoints are both kept.

In this subgraph, compute the size of a maximum matching (the maximum number of pairwise disjoint edges). Let this value be denoted by $f(l, r)$.

You need to compute the following value:

$$\sum_{1 \le l \le r \le n_2} f(l, r) \cdot l \cdot r \cdot ((l \oplus r) + 1),$$

where $\oplus$ denotes the bitwise XOR operation.

Output the value of this sum modulo $998\,244\,353$.

Input

The input contains multiple test cases.

The first line contains a single integer $T$ ($1 \le T \le 2000$), the number of test cases.

For each test case, the first line contains three integers $n_1, n_2, m$ ($1 \le n_1, n_2 \le 5000, 0 \le m \le 10^4$), representing the number of vertices on the left, the number of vertices on the right, and the number of edges.

Each of the next $m$ lines contains two integers $u, v$ ($1 \le u \le n_1, 1 \le v \le n_2$), representing that there is an edge between left vertex $u$ and right vertex $v$.

It is guaranteed that there are no multiple edges, and neither the sum of $n_1$ nor the sum of $n_2$ exceeds $5000$.

Output

For each test case, output a single line containing one integer — the required sum modulo $998\,244\,353$.

Example

Input

4
3 3 5
1 1
2 1
2 2
2 3
3 3
3 4 6
1 2
1 4
2 3
2 1
3 4
3 3
2 2 1
1 2
4 3 5
1 3
2 1
3 3
4 2
4 1

Output

81
529
12
81

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.