Alike Tables
InterviewTime limit1sMemory limit128 MB
Decide whether two tables with distinct entries match after any row and column reorderings.
Problem
An array is filled with integers that are all different from one another. Two operations are allowed on such an array.
- Interchange two rows.
- Interchange two columns.
Two arrays are alike if one of them can be obtained from the other by a sequence of those two operations. Given several pairs of arrays, decide for each pair whether the two arrays are alike.
Input
The first line contains an integer (), the number of pairs of arrays.
The first line of each pair contains two integers and (, ) separated by a single space, the number of rows and the number of columns. The next lines contain the rows of the first array in order, and the lines after that contain the rows of the second array in order. Each of those lines contains integers between and , inclusive. Inside one array all numbers are different.
Output
Print lines. Line contains YES if the two arrays of the -th pair are alike, and NO otherwise. Print in capital letters only.