Gats and the Taller Landing
Gats is practicing jumps on a rooted tree of scratching posts. The posts are numbered , and post is the root. The depth of post is .
Each post has a height and a spring wish .
If Gats is currently at post , he looks only at proper ancestors of . A post is a valid landing post if is an ancestor of and
If at least one valid landing post exists, Gats jumps to the valid landing post with maximum depth, that is, the nearest valid landing post above . If no valid landing post exists, Gats stops.
For every starting post , determine how many jumps Gats makes before stopping.
Input
The first line contains an integer (), the number of scratching posts.
The next lines describe the posts. The -th of these lines contains two integers and (, ), the height and spring wish of post .
Output
Print integers on one line, where is the number of jumps Gats makes before stopping when he starts at post .
Samples
Sample 1
Input
5 10 1 6 3 8 1 4 2 5 4 1 2 3 4
Output
0 1 1 2 1
From post , Gats first jumps to post , then to post , so . From post , only post is a valid landing post, so .