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;
int a, b, d, c, f, e, n, m, k, s, t, bj, c1, c2, c3, min1, max1, dep[2000010],
    head[2000010], son[2000010], l[2000010], r[2000010], siz[2000010],
    answer[2000010], id[2000010], let[2000010], num[20001000];
char q[5];
struct Smary {
  int v, next, w;
} edge[2000010];
void add(int x, int y, int z) {
  edge[d].v = y;
  edge[d].next = head[x];
  edge[d].w = z;
  head[x] = d++;
}
void dfs(int x, int fa) {
  dep[x] = dep[fa] + 1;
  siz[x] = 1;
  l[x] = ++c;
  id[c] = x;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    let[edge[i].v] = let[x] ^ edge[i].w;
    dfs(edge[i].v, x);
    siz[x] += siz[edge[i].v];
    if (siz[edge[i].v] > siz[son[x]]) son[x] = edge[i].v;
  }
  r[x] = c;
}
void dfu(int x, bool bl) {
  for (int i = head[x]; i != -1; i = edge[i].next) {
    if (edge[i].v == son[x]) continue;
    dfu(edge[i].v, false);
    answer[x] = max(answer[x], answer[edge[i].v]);
  }
  if (son[x]) {
    dfu(son[x], true);
    answer[x] = max(answer[x], answer[son[x]]);
  }
  if (num[let[x]]) answer[x] = max(answer[x], num[let[x]] - dep[x]);
  for (int i = 0; i < 22; ++i) {
    if (num[let[x] ^ (1 << i)])
      answer[x] = max(answer[x], num[let[x] ^ (1 << i)] - dep[x]);
  }
  num[let[x]] = max(num[let[x]], dep[x]);
  for (int i = head[x]; i != -1; i = edge[i].next) {
    if (edge[i].v == son[x]) continue;
    for (int j = l[edge[i].v]; j <= r[edge[i].v]; ++j) {
      if (num[let[id[j]]])
        answer[x] = max(answer[x], num[let[id[j]]] + dep[id[j]] - dep[x] * 2);
      for (int l1 = 0; l1 < 22; ++l1) {
        if (num[let[id[j]] ^ (1 << l1)])
          answer[x] = max(
              answer[x], num[let[id[j]] ^ (1 << l1)] + dep[id[j]] - dep[x] * 2);
      }
    }
    for (int j = l[edge[i].v]; j <= r[edge[i].v]; ++j)
      num[let[id[j]]] = max(num[let[id[j]]], dep[id[j]]);
  }
  if (!bl) {
    for (int i = l[x]; i <= r[x]; ++i) num[let[id[i]]] = 0;
  }
}
int main() {
  memset(head, -1, sizeof(head));
  d = 0;
  scanf("%d", &n);
  for (a = 2; a <= n; ++a) {
    scanf("%d", &m);
    scanf("%s", q);
    b = q[0] - 'a';
    add(m, a, 1 << b);
  }
  c = -1;
  dfs(1, 0);
  dfu(1, true);
  for (a = 1; a <= n; ++a) {
    if (a == 1)
      printf("%d", answer[a]);
    else
      printf(" %d", answer[a]);
  }
  printf("\n");
  return 0;
}
