You are given a graph with vertices and queries of three types:
For a given vertex v_i, find the k_i-th smallest vertex number in its connected component. If such a vertex does not exist, return . The connected component of v_i includes all vertices reachable from v_i via edges.
Add an edge between vertices u_i and v_i.
Revert the graph to its state after the x_i-th operation.
Your task is to provide answers for all queries of the first type.
The first line contains three integers , , and (1 \leq n, q \leq 5 \cdot 10^5, 0 \leq g \leq 9).
Each of the following lines contains a query in one of the following formats:
v_i, k_i (1 \leq v_i, k_i \leq n).
v_i, u_i (1 \leq v_i, u_i \leq n).
x_i (0 \leq x_i < i).
For each query of the first type, output the result.
Example 1
Example 2
Example 3
Example 4
( points): n, q \leq 100; no queries of the second and third types.
( points): n, q \leq 100; no queries of the third type.
( points): n, q \leq 100.
( points): n, q \leq 3 \cdot 10^5; for queries of the second type, it is guaranteed that |v_i-u_i|=1; no queries of the third type.
( points): n, q \leq 3 \cdot 10^5, no queries of the third type.
( points): n, q \leq 3 \cdot 10^5; for queries of the second type, it is guaranteed that |v_i-u_i|=1.
( points): n, q \leq 10^5.
( points): n, q \leq 3 \cdot 10^5.
( points): no additional constraints.