题目描述
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Ada has two matrices $A$ and $B$, each with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$).
Ada may perform the following operation any number of times (including zero): choose an integer $i$ ($1 ≤ i ≤ N$), then swap row $i$ and column $i$ in matrix $A$. (Formally, for each valid $j$, she swaps $A_{i, j}$ with $A_{j, i}$.)
Is it possible to transform matrix $A$ into matrix $B$?
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
$N$ lines follow. For each $i$ ($1 ≤ i ≤ N$), the $i$-th of these lines contains $N$ space-separated integers $A_{i, 1}, A_{i, 2}, \ldots, A_{i, N}$.
$N$ more lines follow. For each $i$ ($1 ≤ i ≤ N$), the $i$-th of these lines contains $N$ space-separated integers $B_{i, 1}, B_{i, 2}, \ldots, B_{i, N}$.
------ Output ------
For each test case, print a single line containing the string "Yes" if it is possible to transform $A$ into $B$ or "No" if it is impossible (without quotes).
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 2^{10}$
$1 ≤ A_{i, j}, B_{i, j} ≤ 10^{9}$ for each valid $i, j$
the sum of $N^{2}$ over all test cases does not exceed $3 \cdot 10^{6}$
----- Sample Input 1 ------
1
3
1 2 3
4 5 6
7 8 9
1 2 7
4 5 8
3 6 9
----- Sample Output 1 ------
Yes
----- explanation 1 ------
Example case 1: We can swap the second row with the second column and in the resulting matrix, swap the first row with the first column.
输入格式
见题面
输出格式
见题面