Subtree MEX

Limits 2s, 1.0 GB

You will be given a balanced binary tree of NN nodes. Each of the nodes of the tree will contain a non-negative integer value. Then, you will be asked to perform QQ queries on the given tree. Each of the queries will be one of the two types described below.

Definition:\textbf{\underline{Definition}}:

Input

The first line of the input will contain a positive integer NN (1N105)(1 \leq N \leq 10^{5}) which denotes the number of nodes in the tree. The nodes of the tree are numbered from 11 to NN.

The next line will contain NN integers. The ithi^{th} positive integer is the parent node of ithi^{th} node. If the value is 1-1 then the ithi^{th} node is the root node of the tree.

Then, there will be a line containing NN positive integers. The jthj^{th} positive integer is the value assigned to the jthj^{th} node. All the values will be 32-bit non-negative integers.

The fourth line of the input will contain a positive integer QQ (1Q3×105)(1 \leq Q \leq 3 \times 10^{5}) which denotes the number of queries. Each of the next QQ lines will contain one of the two types of queries described in the statement.

Output

Print the MEX value for each 2nd2^{nd} type of query in a new line.

Sample

InputOutput
3
-1 1 1
0 1 2
5
2 1
2 2
2 3
1 1 3
2 1
3
0
0
0