At the end of class, the teacher announces that today's homework will be assigned using a ladder game. There are vertical lines on the board, numbered from left to right. The amount of homework assigned to a student is written at the bottom of the line where they finish.
Initially, there are no horizontal rungs. The teacher adds rungs one at a time, each connecting adjacent vertical lines and at height . Heights are measured from the top, so a smaller value of is higher up. Once added, a rung is never removed.
To play, start at the top of a vertical line and move downward. Whenever you encounter a rung connected to your current line, you must cross it to the other vertical line and then continue downward below that height. If you encounter no more rungs, you finish at the bottom of your current line.
For example, suppose a rung at height connects lines and , and another at height connects lines and . Starting from line , you cross to line at height , then to line at height , and finish on line .
While the teacher is adding rungs, Dejavu wants to know where different starting lines lead in the current ladder. Process queries of the following two types in the given order:
No vertical line is connected to more than one rung at the same height. Multiple rungs may have the same height if they do not share a vertical line.
The input is given in the following format.
For each type query, output the number of the destination vertical line on a separate line. Output answers in test case order and, within each test case, in query order. Output nothing for a test case with no type queries.
Both of the first two queries cross from line to line at height . For the second query, the rung at height also exists, but it is not encountered because the path is still on line at that height.
The first line contains the number of test cases . Each test case is given in the following format.
The first line of each test case contains the number of vertical lines and the number of queries . Each of the next lines contains a query in the form or , in the order to be processed. Test cases are independent, and each starts with no rungs.
After the last rung is added, the rungs connect at height , at height , and at height . Starting from line , the path goes and finishes on line . Starting from line , it crosses to line at height and finishes there.
In the first test case, starting from line leads to line before the rung is added and to line afterward.
The second test case has no type queries, so it produces no output.
The third test case starts with a new ladder containing no rungs. Both paths finish on their starting lines, and .
The first two rungs are both at height . This is allowed because they connect and and share no vertical line.
The rung added at height is above both earlier rungs. Immediately after it is added, a path starting from line goes , while one starting from line goes .
After the final rung at height is added, the path starting from line crosses once more from line to line .