eolymp
bolt
Try our new interface for solving problems

Table

Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB

Let us consider an array of size n×m filled with pair wise different integers. The following operations are allowed on the array:

  1. Interchanging two rows,

  2. Interchanging two columns.

We call two arrays alike if one of them can be obtained from the other by a sequence of the above two operations. Write a program that for a given set of pairs of arrays tells which pairs are alike.

Giriş verilənləri

The first line of the standard input contains an integer t (1t10) denoting the number of test cases which represent the number of pairs of arrays. The first line of each test case holds two integers n and m (1n1000 and 1 m1000), separated by a single space. n and m denote the number of rows and columns of the arrays, respectively. The next n lines represent n rows of the first array and the following n lines represent n rows of the second array. Each line holds m array items where each values between -1000000 and 1000000 inclusive. All numbers occurring in either of the arrays are pair wise different.

Çıxış verilənləri

Your program should print out t lines to the standard output. The k-th of these should hold one word: "YES" if the arrays of the k-th pair are alike, or "NO" otherwise (in capital letter only).

Nümunə

Giriş verilənləri #1
2
4 3
1 2 3
4 5 6
7 8 9
10 11 12
11 10 12
8 7 9
5 4 6
2 1 3
2 2
1 2
3 4
5 6
7 8
Çıxış verilənləri #1
YES
NO
Mənbə ACM-ICPC Malaysia al-Khawārizmī Programming Contest 2011