Quiet Yarn Routes
Gats has a cat tree with cushions numbered . Cushion is the top cushion. For each with , there is a single passage from cushion to cushion , and that passage has yarn color .
A cushion is an ancestor of a cushion if or following passages upward from can reach .
For a fixed cushion , Gats may choose any ancestor of and walk downward along the unique path from to . The chosen route is quiet if no yarn color appears on more than one passage of that path. If , the path contains no passages and is quiet.
For every cushion with , let be the number of ancestors of for which the route from to is quiet. Compute all values .
Input
The first line contains an integer (), the number of cushions.
The next lines describe cushions in this order. The line for cushion contains two integers and (, ), meaning that the passage from cushion to cushion has yarn color .
Output
Print integers in one line, separated by spaces.
Samples
Sample 1
Input
5 1 7 1 3 2 3 4 7
Output
1 2 2 3 3
For cushion , the ancestors are . The route from to uses colors , so it is not quiet. Starting from , , or is quiet, so .