I. Impressive Internship
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

The company Kommunikation-Ist-Toll (KIT) has achieved world wide fame for its various messenger apps – they have already published $$$10^9$$$ of those! Obviously, this is a lot of work for the employees. Thus, KIT is always trying to recruit ICPC participants for internships.

Internally, KIT is organized in a tree structure: Employee $$$1$$$ is the CEO, and every other employee $$$i$$$ has a direct boss numbered $$$p_i$$$. Obviously, KIT uses its own messengers for company intern communication. In particular, employee $$$i$$$ uses the messenger app with id $$$x_i$$$ to communicate with the direct boss $$$p_i$$$.

When someone is doing an internship at KIT, they are assigned some direct boss as well as the messenger app used for communication with this boss. Since KIT offers great jobs$$$^{\text{∗}}$$$, all interns stay at KIT and continue working as ex-interns. Then, they can also become the direct boss of some new interns.

To get the internship at KIT, you have to solve the following interview problem about efficiently simulating the company structure:

  • Initially, there is only one employee – the CEO numbered $$$1$$$.
  • Then, your program has to process $$$q$$$ events:
    • 1 p x someone is doing an internship at KIT and is assigned direct boss $$$p$$$, with whom they communicate via the messaging app with id $$$x$$$. New interns / employees are numbered subsequently. I.e., the $$$i$$$-th intern gets number $$$i+1$$$.
    • 2 a b suppose that employee $$$a$$$ sends a message to $$$b$$$. This message is passed on the direct route from $$$a$$$ to $$$b$$$ along the tree structure. Is there a messenger app which is used an odd number of times during this process? If yes, output the largest id of such an app. Otherwise, output $$$-1$$$.
  • Your program has to process those events online, i.e., after an event of type $$$2$$$, it has to compute the answer before receiving the next event.

$$$^{\text{∗}}$$$For example, you are allowed to play table football during work.

Interaction

The interactor first sends one line with one integer $$$q$$$ ($$$1 \leq q \leq 2 \cdot 10^5$$$), describing the number of events which you have to simulate.

After this, you receive $$$q$$$ lines with events described as above in the following format:

  • 1 p x  ($$$1 \leq p \leq n', 1 \leq x \leq 10^9$$$).
  • 2 a b  ($$$1 \leq a, b \leq n'$$$).

Here, $$$n'$$$ represents the number of employees KIT currently employs prior to this interaction. (Initially, $$$n' = 1$$$) For each event of type 2, output and flush its answer in one line, before reading the next event.

Let $$$q_1, q_2$$$ be the number of events of type $$$1$$$ and $$$2$$$, respectively. It is guaranteed that $$$q_1, q_2 \leq 10^5$$$.

Example
Input
10
1 1 2
1 2 2
2 1 3
2 2 1
1 1 2
2 3 4
1 4 3
2 3 4
1 5 1
2 3 6
Output
-1
2
2
2
3