시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 256 MB 2 2 2 100.000%

문제

While you weren't watching, your N robots have developed a life of their own and spread throughout your hometown. Each of your hometown's N intersections (numbered 0,…,N-1) contains exactly one robot. On each intersection i, there is exactly one red signpost pointing to an intersection, ri ≠ i, and exactly one green signpost pointing to an intersection gi ≠ i. When you press the red button on your remote control, each robot will move to the intersection indicated by the red signpost (robots at intersection i move to ri). When you press the green button, each robot will move to the intersection indicated by the green signpost (robots at intersection i move to gi). Write a program that determines whether you can make the robots all meet at the same intersection at the same time via some sequence of commands on your remote control.

입력

The first line of input contains a single decimal integer P, (1 ≤ P ≤ 500), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists three lines of input as follows:

  • The first line contains the data set number, K, followed by a single integer N which is the number of intersections.
  • The second line contains N space separated integers r0, …, rN-1 (0 ≤ ri ≤ N-1 and ri ≠ i).
  • The third line contains N space separated integers g0, …, gN-1 (0 ≤ gi ≤ N-1 and gi ≠ i).

On some intersections, both signposts might point the same way (i.e. ri = gi).

출력

For each data set there is one line of output. The single output line consists of the string “YES” if you can make all robots meet or “NO” otherwise.

예제 입력

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

예제 출력

1 NO
2 YES

힌트

Note: For the second case, the button press sequence GREEN, RED, RED, GREEN makes all robots meet at intersection 2.