Just in case somebody missed it: we have wonderful girls in Arpa’s land.

Arpa has a rooted tree (connected acyclic graph) consisting of n vertices. The vertices are numbered 1 through n, the vertex 1 is the root. There is a letter written on each edge of this tree. Mehrdad is a fan of Dokhtar-kosh things. He call a string Dokhtar-kosh, if we can shuffle the characters in string such that it becomes palindrome.

<image>

He asks Arpa, for each vertex v, what is the length of the longest simple path in subtree of v that form a Dokhtar-kosh string.

Input

The first line contains integer n (1 ≤ n ≤ 5·105) — the number of vertices in the tree.

(n - 1) lines follow, the i-th of them contain an integer pi + 1 and a letter ci + 1 (1 ≤ pi + 1 ≤ i, ci + 1 is lowercase English letter, between a and v, inclusively), that mean that there is an edge between nodes pi + 1 and i + 1 and there is a letter ci + 1 written on this edge.

Output

Print n integers. The i-th of them should be the length of the longest simple path in subtree of the i-th vertex that form a Dokhtar-kosh string.

Examples

Input

4
1 s
2 a
3 s


Output

3 1 1 0 

Input

5
1 a
2 h
1 a
4 h


Output

4 1 0 1 0 
#include <bits/stdc++.h>
using namespace std;
struct TT {
  int fa, size, son, d, f;
} t[500010];
int dfn[500010], R[500010], id;
int O[500010];
struct node {
  int y, k, next;
} a[500010];
int first[500010], len;
int v[5000010];
int T[500010], tl;
int ans[500010];
void ins(int x, int y, int k) {
  a[++len].y = y;
  a[len].k = k;
  a[len].next = first[x];
  first[x] = len;
}
void dfs(int x) {
  int k, y;
  dfn[x] = R[x] = ++id;
  O[id] = x;
  t[x].size = 1;
  for (k = first[x]; k; k = a[k].next) {
    y = a[k].y;
    t[y].fa = x;
    t[y].d = t[x].d + 1;
    t[y].f = t[x].f ^ (1 << a[k].k);
    dfs(y);
    R[x] = R[y];
    t[x].size += t[y].size;
    if (t[y].size > t[t[x].son].size) t[x].son = y;
  }
}
void DFS(int x) {
  int k, y, i, j, s = 0;
  for (k = first[x]; k; k = a[k].next) {
    y = a[k].y;
    if (y == t[x].son) continue;
    DFS(y);
    while (tl) v[T[tl--]] = 0;
    ans[x] = max(ans[x], ans[y]);
  }
  if (t[x].son) {
    DFS(t[x].son);
    ans[x] = max(ans[x], ans[t[x].son]);
  }
  for (k = first[x]; k; k = a[k].next) {
    y = a[k].y;
    if (y == t[x].son) continue;
    for (i = dfn[y]; i <= R[y]; i++) {
      int p = O[i];
      if (v[t[p].f]) s = max(s, v[t[p].f] + t[p].d);
      for (j = 1; j <= 22; j++)
        if (v[t[p].f ^ (1 << j - 1)])
          s = max(s, v[t[p].f ^ (1 << j - 1)] + t[p].d);
    }
    for (i = dfn[y]; i <= R[y]; i++) {
      int p = O[i];
      T[++tl] = t[p].f;
      v[t[p].f] = max(v[t[p].f], t[p].d);
    }
  }
  if (v[t[x].f]) s = max(s, v[t[x].f] + t[x].d);
  for (i = 1; i <= 22; i++)
    if (v[t[x].f ^ (1 << i - 1)]) s = max(s, v[t[x].f ^ (1 << i - 1)] + t[x].d);
  T[++tl] = t[x].f;
  v[t[x].f] = max(v[t[x].f], t[x].d);
  ans[x] = max(ans[x], s - 2 * t[x].d);
}
int main() {
  int n, x, i, j;
  char c;
  scanf("%d", &n);
  for (i = 2; i <= n; i++) {
    scanf("%d %c", &x, &c);
    ins(x, i, c - 'a');
  }
  t[1].d = 1;
  dfs(1);
  DFS(1);
  for (i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
