QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 32 MB Total points: 100

#594. Arrays

统计

Let us consider an array of size $n \times m$ filled with pairwise different integers. The following operations are allowed on the array:

  • interchanging two rows,
  • interchanging two columns.

We call two arrays alike if one of them can be obtained from the other by a sequence of aforementioned operations.

Write a programme that for a given set of pairs of arrays tells which pairs are alike.

Input

The first line of the standard input contains one integer $t$ ($1 ≤ t ≤ 10$) denoting the number of pairs of arrays. Then descriptions of successive array pairs follow in subsequent lines.

Each description starts with a line holding two integers $n$ and $m$ ($1 ≤ n,m ≤ 1\,000$), separated by a single space, that denote the common number of rows and columns of the arrays, respectively.

The $n$ lines that follow describe the first array. In the $i$-th of them there are $m$ integers $a_{i,j}$ ($-1\,000\,000 ≤ a_{i,j} ≤ 1\,000\,000$), separated by single spaces, that denote the numbers in the $j$-th row of the first array.

The next $n$ lines describe the second array. In the $i$-th of them there are $m$ integers $b_{i,j}$ ($-1\,000\,000 ≤ b_{i,j} ≤ 1\,000\,000$), separated by single spaces, that denote the numbers in the $i$-th row of the second array.

All the numbers occuring in either of the arrays are pairwise different.

Output

Your programme should print out $t$ lines to the standard output. The $k$-th of these should hold one word: "TAK" (yes in Polish) if the arrays of the $k$-th pair are alike, or "NIE" (no in Polish) otherwise.

Example

Input

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

Output

TAK
NIE

The arrays forming the first pair are alike. To transform the first array into the other, it is enough to interchange the first two columns, and then the first row with last one and the second row with the third one.

The arrays forming the second pair are not alike. To see this, note that the sets of values in their cells are different.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.