QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#5825. Matrix

统计

You are given three $n \times n$ matrices $A, B, C$ multiple times. You need to determine whether $A \times B$ is equal to $C$ modulo $998244353$.

Here, $\times$ denotes matrix multiplication, where $C_{i,j} = \sum_{k=1}^{n} A_{i,k} B_{k,j}$.

The input size for this problem is large; it is recommended to use fast I/O.

Input

The first line contains a positive integer $T$, representing the number of test cases.

The input then contains $T$ test cases. For each test case, the first line is a positive integer $n$, representing the size of the matrices.

The next $n$ lines, each containing $n$ integers, represent matrix $A$.

The next $n$ lines, each containing $n$ integers, represent matrix $B$.

The next $n$ lines, each containing $n$ integers, represent matrix $C$.

Output

Output $T$ lines, each containing either "Yes" or "No", indicating whether $A \times B$ is equal to $C$ modulo $998244353$.

Constraints

  • For 20% of the data, $\sum n \le 300$.
  • For another 20% of the data, the number of positions where $A_{i,j} \neq 0$ does not exceed $n$.
  • For 100% of the data, $1 \le T, n \le 3000$, $\sum n \le 3000$, and $0 \le A_{i,j}, B_{i,j}, C_{i,j} < 998244353$.

Examples

Input 1

3
1
2
3
6
2
1 2
3 4
5 6
7 8
19 22
43 51
2
1111111 2222222
3333333 4444444
5555555 6666666
7777777 8888888
39625305 256038638
772687616 944903942

Output 1

Yes
No
Yes

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.