시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
3 초 128 MB 0 0 0 0.000%

문제

Byteland is known for wandering flea trainers. Tamed fleas are taught to dance. They make precise leaps in the rhythm of music. On the table the trainer puts in a row numbered coins, but it's not assumed that they are arranged in any specific order. On each coin there is an inscription of the form “i→j”; i is the number of this coin and j is the number of the coin on which a flea should leap if it sits on this coin. Then the trainer puts one flea on each coin and turns on the music. The fleas, while dancing, follow the rhythm of the music; i.e. at each beat of music each flea leaps directly to the coin with number equal to the j-number written on the coin it is sitting on. During the dance it may happen that many fleas sit on the same coin. In this case they continue their performance together. Let's assume that we have n coins and n fleas. As soon as we say what numbers are written on the coins 1,2,…,n, we will have the performance fully determined. However, two different sets of coins may give the same performance, if only we arrange them in appropriate order.

Let us consider the performance on three coins. If the leaps are performed in the following way: from the first coin to the second one, from the second coin to the third one, from the third coin to the first one (we denote this: 1→2,2→3,3→1); then the fleas will dance in a circle and no two of them will ever meet on one coin. For example, the dance 1→2,2→3,3→3 is different, because it will make all the fleas meet on the third coin after two beats of music and it will make them jump only on the third coin forever.

However, the sets 1→2,2→3,3→2,4→4 and 1→1,2→3,3→2,4→3 are of the same type. If you put these coins in the row - the first set from left to right and the second from right to left - you would see the same performance.

The spectators are discontent if the fleas perform in the same way for the second time. Hence there is needed a program which:

  • reads from the standard input the number of test cases,
  • for each case, reads from the standard input the description of two sets of coins and verifies, whether or not, one can arrange the coins from these sets on the table in such a way, that fleas would give the same performance on both sets of coins,
  • writes the result to the standard output.

입력

In the first line of the standard input there is written one integer d equal to the number of test cases, 1 ≤ d ≤ 100. In the following 3d lines the test cases are described - each case occupies three consecutive lines. The first of these three contains one integer n, 1 ≤ n ≤ 2,000, equal to the number of coins. Each of the remaining two lines is a description of a set of n coins in a form of n integers from the interval 1…n, separated by single spaces; the i-th integer denotes the number of a coin that flea must leap to when it seats on the i-th coin.

출력

For each of the test cases from the input your program should write to the standard output exactly one line containing exactly one letter:

  • T - if one can arrange on a table the coins from both sets in a way, that makes fleas perform in the same way,
  • N - otherwise.

예제 입력

2
3
2 3 1
2 3 3
4
2 3 2 4
1 3 2 3

예제 출력

N
T

힌트