A research project is being conducted to study the evolution of species. In the beginning, there exists a single species, numbered as index .
The process of evolution may be expressed as a tree: At any point, an existing species may evolve to form a new species - said existing species is the new species' parent, and the new species is the existing species' child. Whenever this happens, we assign the new species the next integer index.
For example, in Figure 1 below, species initially evolves to create species and ; after which species evolves to create , , and ; species evolves to species ; and finally species forms species and .
Figure 1
For any species with at least one child, we can assign to it a major branch leading to one of its children - the branches leading to its other children are then considered minor branches. Assigning a major branch to all eligible species defines a classification scheme for the evolutionary tree.
We can judge the efficiency of an evolutionary scheme by measuring its overall evolutionary complexity. The evolutionary complexity between two species A and B is defined as the number of minor branches on the shortest path between them; while the evolutionary complexity of an entire classification scheme is the maximum evolutionary complexity between any pair of its species.
Of course, schemes with a lower evolutionary complexity are easier to analyse - so we would like to minimise these evolutionary complexities.
The research project spans days. Before the first day, only species exists. Then, on each day, one of two kinds of studies is conducted:
: Evolution is induced in species , creating a new species with the next available index as a direct child of . This study occurs times.
: We seek to analyse the evolutionary subtree containing species and its descendants. Output the minimum evolutionary complexity out of all possible classification schemes of this subtree. This study occurs times.
Your task is to determine the minimum complexity, for all studies of type .
Input format
The first line of input consists of a single integer , the number of studies over the project.
lines of input follow. The of these lines contains 2 integers, representing a valid study as described in the task description.
Output format
Output lines, one for each study of type - each containing a single integer, the minimum evolutionary complexity of the required evolutionary subtree.
Limits
All will refer to species that currently exist.
Subtask #
Score
Constraints
1
7
2
11
3
5
The parent of species is .
4
21
Each species will have no more than 2 direct children.