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;
const int inf = 1e9 + 7;
int to[1000001], fdkjg[1000001], first[500001], e1 = 0, pos[500001];
int ans[500001], mi[30], dfn[500001], dfs[500001], w[1000001], n;
int size[500001], son[500001], deep[500001], f[5000001], t = 0;
void insert(int o, int p, int q) {
  to[e1] = p;
  w[e1] = q;
  fdkjg[e1] = first[o];
  first[o] = e1++;
}
void dfs1(int o, int p) {
  size[o] = 1;
  deep[o] = deep[p] + 1;
  dfs[++t] = o;
  pos[o] = t;
  for (int i = first[o]; i != -1; i = fdkjg[i])
    if (to[i] != p) {
      dfn[to[i]] = dfn[o] ^ w[i];
      dfs1(to[i], o);
      if (size[to[i]] > size[son[o]]) son[o] = to[i];
      size[o] += size[to[i]];
    }
}
void dfs2(int o, int p, int keep) {
  ans[o] = 0;
  for (int i = first[o]; i != -1; i = fdkjg[i])
    if ((to[i] != p) && (to[i] != son[o])) {
      dfs2(to[i], o, 0);
      ans[o] = max(ans[o], ans[to[i]]);
    }
  if (son[o]) {
    dfs2(son[o], o, 1);
    ans[o] = max(ans[o], ans[son[o]]);
  }
  for (int i = first[o]; i != -1; i = fdkjg[i])
    if ((to[i] != p) && (to[i] != son[o])) {
      for (int j = pos[to[i]]; j < pos[to[i]] + size[to[i]]; j++) {
        ans[o] = max(ans[o], deep[dfs[j]] + f[dfn[dfs[j]]] - 2 * deep[o]);
        for (int k = 0; k <= 21; k++)
          ans[o] = max(ans[o],
                       deep[dfs[j]] + f[dfn[dfs[j]] ^ (1 << k)] - 2 * deep[o]);
      }
      for (int j = pos[to[i]]; j < pos[to[i]] + size[to[i]]; j++)
        f[dfn[dfs[j]]] = max(f[dfn[dfs[j]]], deep[dfs[j]]);
    }
  ans[o] = max(ans[o], f[dfn[o]] - deep[o]);
  for (int k = 0; k <= 21; k++)
    ans[o] = max(ans[o], f[dfn[o] ^ (1 << k)] - deep[o]);
  f[dfn[o]] = max(f[dfn[o]], deep[o]);
  if (!keep)
    for (int i = pos[o]; i < pos[o] + size[o]; i++) f[dfn[dfs[i]]] = -inf;
}
int main() {
  memset(first, -1, sizeof(first));
  for (int i = 0; i <= 5000000; i++) f[i] = -inf;
  mi[0] = 1;
  for (int i = 1; i <= 21; i++) mi[i] = mi[i - 1] * 2;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    char ch = getchar();
    while ((ch < 'a') || (ch > 'v')) ch = getchar();
    insert(x, i, mi[ch - 'a']);
    insert(i, x, mi[ch - 'a']);
  }
  dfn[1] = deep[0] = 0;
  dfs1(1, 0);
  dfs2(1, 0, 0);
  for (int i = 1; i < n; i++) printf("%d ", ans[i]);
  printf("%d\n", ans[n]);
  return 0;
}
