Drzewa

No attempts yetTime limit1sMemory limit128 MB

Problem

West of the base lies an area holding n1n-1 trees numbered from 22 to nn. Node 11 is not a tree but the base, and it sits east of every tree.

From each tree exactly one path leads east, to the base or to another tree, and there is exactly one route from the base to each tree. The whole structure is therefore a tree rooted at the base (node 11): each tree's east path goes to its parent, while the paths leading west go to its children.

Every path has a difficulty written as a single lowercase letter, where aa is the easiest and zz is the hardest.

A mission starts at some tree (or the base) and keeps moving west (toward children) for as long as possible: from the starting point it goes down one path at a time until it reaches a tree that has no westward path. Writing the difficulties of the traversed paths in order gives the mission's difficulty string.

To compare two missions, compare their difficulty strings lexicographically. At the first position where they differ, the mission taking the harder (lexicographically larger) path is harder. If one string equals the beginning of the other and is longer, the longer one is harder. If two missions have identical difficulty strings, the one ending at the tree with the smaller number is considered harder.

For every tree and for the base, determine at which tree the hardest mission starting there ends.

Input

The first line contains an integer nn (1n5000001 \le n \le 500000).

Each of the next n1n-1 lines, the ii-th of them corresponding to 2in2 \le i \le n, contains an integer pip_i (1pii11 \le p_i \le i-1) and a lowercase letter cic_i separated by a space. pip_i is the number of the tree (or the base) reached by following the east path from tree ii, and cic_i is that path's difficulty.

Output

Print nn integers d1,d2,,dnd_1, d_2, \dots, d_n, each on its own line. did_i is the number of the tree at which the hardest mission starting at tree (or base) ii ends. If no path leads west out of ii, print 00.