A binary tree is a set of nodes, each of which can have a left child and a right child. The root node is not a child of any other node. By starting at the root node and moving to one of the children each time, it is possible to reach any node. A subtree of a node is a set of nodes that can be reached from it.
There are three common binary tree traversals: pre-order, in-order and post-order traversals.
A pre-order traversal order is an order in which nodes are visited by the following recursive procedure:
An in-order traversal visits the root node between traversals of its left and right subtrees, a post-order traversal visits the root node after traversals of its left and right subtrees.
These traversals can be combined as follows: let us assign a number $$$-1$$$, $$$0$$$ or $$$1$$$ to each node. Each number denotes at which moment the node is visited:
If each node is assigned $$$-1$$$, this is a pre-order traversal, $$$0$$$ — an in-order traversal, $$$1$$$ — a post-order traversal.
You are given a binary tree consisting of $$$n$$$ nodes numbered with integers from $$$1$$$ to $$$n$$$. The root is the node number $$$1$$$. Initially each node is assigned $$$-1$$$.
You have to process $$$q$$$ queries of two different types:
For each query of the second type, output the answer to it.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 100\,000$$$).
The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$L_i$$$ and $$$R_i$$$ ($$$0 \le L_i, R_i \le n$$$) — numbers of the left and right child of node $$$i$$$. If $$$L_i = 0$$$, node $$$i$$$ does not have a left child. If $$$R_i = 0$$$, node $$$i$$$ does not have a right child.
It is guaranteed that $$$L_i$$$ and $$$R_i$$$ describe a valid binary tree.
The $$$i$$$-th of the next $$$q$$$ lines describes the $$$i$$$-th query. The line starts with an integer $$$t$$$ ($$$t \in \{1, 2\}$$$) — type of the query.
In the query of the first type, the rest of the line contains three integers $$$l$$$, $$$r$$$ and $$$x$$$ ($$$1 \le l \le r \le n$$$, $$$x$$$ equals $$$-1$$$, $$$0$$$ or $$$1$$$) — boundaries of the segment of nodes and the number assigned to them.
In the query of the second type, the rest of the line contains an integer $$$i$$$ ($$$1 \le i \le n$$$) — number of the node, the position of which you have to find.
For each query of the second type, output the position of node $$$i$$$ in the current traversal order.
For each query of the second type, output the position of node $$$i$$$ in the current traversal order.
TBD
5 53 40 05 20 00 02 21 1 3 12 51 3 3 02 3
4 1 2
In the first example, the traversal order changes as follows: