#P3492. Table Similarity Determination

    ID: 16747 Type: Default 1000ms 256MiB

Table Similarity Determination

Table Similarity Determination

Given two n × m tables filled with distinct integers, you are allowed to perform the following operations on a table:

  1. Swap any two rows.
  2. Swap any two columns.

Two tables are considered similar if one can be transformed into the other by a sequence of these operations.

Your task is to determine, for each given pair of tables, whether they are similar.

Note: Any formula present is rendered in \(\LaTeX\) format. For example, an \(n \times m\) table is written as \(n \times m\).

inputFormat

The first line contains a single integer \(T\) (\(T \ge 1\)) representing the number of test cases.

Each test case begins with a line containing two integers \(n\) and \(m\) (\(1 \le n, m \le 1000\)) separated by a space.

The next \(n\) lines each contain \(m\) distinct integers representing the first table.

This is followed by another \(n\) lines, each containing \(m\) distinct integers representing the second table.

outputFormat

For each test case, output a single line containing "YES" if the two tables are similar, or "NO" otherwise.

sample

3
2 2
1 2
3 4
1 2
3 4
2 2
1 2
3 4
1 2
4 3
3 3
1 2 3
4 5 6
7 8 9
1 3 2
7 9 8
4 6 5
YES

NO YES

</p>