You are given an array of size n×m filled with pairwise distinct integers. The following two operations may be applied to the array:
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.
The first line contains one integer t (1≤t≤10), the number of array pairs. Descriptions of the pairs follow.
Each description begins with a line containing two integers n and m (1≤n,m≤1000), separated by a single space, the common number of rows and columns of the two arrays.
The next n lines describe the first array; the i-th of them contains m integers aij (−106≤aij≤106), separated by single spaces, the values in the i-th row of the first array.
The following n lines describe the second array in the same way; the integers in its i-th line are denoted bij.
All numbers within a single array are pairwise distinct.
Print t lines, one per pair. The k-th line should contain TAK if the two arrays of the k-th pair are alike, or NIE otherwise. (TAK and NIE mean "yes" and "no", respectively.)
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.