Special graph#7478

Special graph

1 second
64 megabytes
Hard (≈1650)

You are given a directed graph with vertices. The special thing about the graph is that each vertex has at most one outgoing edge. Your task is to answer the following two types of queries:

Input

First line contains a natural number (n \le 10^5) - the number of vertices in the graph. The following line contains integer numbers, -th number is next_i (0 \le next_i \le n), meaning that there is an edge from vertex to vertex next_i. If next_i = 0, assume that there is no outgoing edge from vertex . Third line contains a natural number (m \le 10^5) - the number of queries. The following contain a query each. Queries are given in the manner described above.

Output

On the -th line output the answer for the -th query of type 2 a b.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading