Ranks in groups

No attempts yetTime limit5sMemory limit256 MB

Problem

There are NN students. For each ii with 1iN1 \le i \le N, student ii scores ii points on the exam. The students are split into groups, and at the start group ii holds only student ii.

Write a program that supports the following two operations.

  1. Group merge: given two group numbers XX and YY, move every student of group YY into group XX. After the merge, group YY no longer exists.
  2. Query: given a student number JJ, find the rank of student JJ inside the group that holds student JJ. Within a group, the student with the highest score has rank 1, the student with the second highest score has rank 2, and so on.

Each test case contains LL operations.

Input

The first line contains an integer TT (T5T \le 5), the number of test cases. Each test case follows in the format below.

The first line of a test case contains two integers NN and LL (1N1000001 \le N \le 100\,000, 1L2000001 \le L \le 200\,000).

Each of the next LL lines describes one operation. The line starts with an integer KK, the type of the operation.

  • If K=1K = 1, two more integers XX and YY follow on the same line. Merge the students of group YY into group XX.
  • If K=2K = 2, one more integer JJ follows. Print the rank of student JJ inside the group that holds student JJ.

Both groups given in a merge operation still exist at that moment, and XX and YY are different.

Output

For each query operation, print the rank of that student on its own line. Print the answers of all test cases in the order the queries appear.