Arrays

No attempts yetTime limit4sMemory limit128 MB

Problem

You are given an array of size n×mn \times m filled with pairwise distinct integers. The following two operations may be applied to the array:

  1. interchange two rows,
  2. interchange two columns.

Two arrays are called alike if one of them can be obtained from the other by a sequence of the operations above.

Given several pairs of arrays, write a program that determines, for each pair, whether the two arrays are alike.

Input

The first line contains one integer tt (1t101 \le t \le 10), the number of array pairs. Descriptions of the pairs follow.

Each description begins with a line containing two integers nn and mm (1n,m10001 \le n, m \le 1000), separated by a single space, the common number of rows and columns of the two arrays.

The next nn lines describe the first array; the ii-th of them contains mm integers aija_{ij} (106aij106-10^6 \le a_{ij} \le 10^6), separated by single spaces, the values in the ii-th row of the first array.

The following nn lines describe the second array in the same way; the integers in its ii-th line are denoted bijb_{ij}.

All numbers within a single array are pairwise distinct.

Output

Print tt lines, one per pair. The kk-th line should contain TAK if the two arrays of the kk-th pair are alike, or NIE otherwise. (TAK and NIE mean "yes" and "no", respectively.)

Note

Interchanging rows or columns preserves the relations "lies in the same row" and "lies in the same column". Hence, for two arrays to be alike, they must first contain the same set of values, and any values sharing a row (or a column) in one array must also share a row (or a column) in the other. Checking whether the row-to-row and column-to-column correspondences can be fixed without contradiction settles whether the arrays are alike.