#P10102. Matrix Multiplication Modulo Verification

    ID: 12087 Type: Default 1000ms 256MiB

Matrix Multiplication Modulo Verification

Matrix Multiplication Modulo Verification

You are given three \(n \times n\) matrices \(A\), \(B\) and \(C\). Your task is to determine whether \(A \times B\) is equal to \(C\) under modulo \(998244353\). The matrix multiplication is defined as:

\[ C_{ij} = \sum_{k=1}^{n} A_{ik} \times B_{kj} \quad (\bmod\;998244353) \]

Note: Due to the large input size, it is recommended to use fast input methods.

inputFormat

The first line contains an integer \(T\) denoting the number of test cases. Each test case is described as follows:

  1. The first line contains an integer \(n\) (the size of the matrices).
  2. The next \(n\) lines each contain \(n\) integers representing the matrix \(A\).
  3. The following \(n\) lines each contain \(n\) integers representing the matrix \(B\).
  4. The next \(n\) lines each contain \(n\) integers representing the matrix \(C\).

outputFormat

For each test case, output a single line containing Yes if \(A \times B \equiv C\) modulo 998244353, otherwise output No.

sample

3
2
1 2
3 4
1 0
0 1
1 2
3 4
2
1 2
3 4
1 2
3 4
7 10
15 22
2
1 2
3 4
1 2
3 4
7 10
15 23
Yes

Yes No

</p>