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 n, m, tot, num;
int fa[2000000], dep[2000000], son[2000000], dis[2000000], top[2000000],
    ed[2000000], bel[2000000], ans[2000000];
int fire[2000000], nex[2 * 2000000], to[2 * 2000000], val[2 * 2000000],
    siz[2000000];
int f[2000000 * 10];
void add(int u, int v, int w) {
  nex[++tot] = fire[u];
  fire[u] = tot;
  to[tot] = v;
  val[tot] = w;
  return;
}
void dfs(int x, int fr) {
  fa[x] = fr;
  dep[x] = dep[fr] + 1;
  top[x] = ++num;
  bel[num] = x;
  siz[x] = 1;
  for (int i = fire[x]; i; i = nex[i]) {
    int v = to[i];
    if (v == fr) continue;
    dis[v] = dis[x] ^ val[i];
    dfs(v, x);
    siz[x] += siz[v];
    if (siz[v] > siz[son[x]]) son[x] = v;
  }
  ed[x] = num;
}
void dfs1(int x, int keep) {
  for (int i = fire[x]; i; i = nex[i]) {
    int v = to[i];
    if (v == fa[x] || v == son[x]) continue;
    dfs1(v, 0);
    ans[x] = max(ans[v], ans[x]);
  }
  if (son[x]) dfs1(son[x], 1), ans[x] = max(ans[x], ans[son[x]]);
  if (f[dis[x]]) ans[x] = max(ans[x], f[dis[x]] - dep[x]);
  for (int i = 0; i < 22; i++) {
    if (f[dis[x] ^ (1 << i)])
      ans[x] = max(ans[x], f[dis[x] ^ (1 << i)] - dep[x]);
  }
  f[dis[x]] = max(dep[x], f[dis[x]]);
  for (int i = fire[x]; i; i = nex[i]) {
    int v = to[i];
    if (v == fa[x] || v == son[x]) continue;
    for (int j = top[v]; j <= ed[v]; j++) {
      int u = bel[j];
      if (f[dis[u]]) ans[x] = max(ans[x], dep[u] + f[dis[u]] - 2 * dep[x]);
      for (int k = 0; k < 22; k++) {
        if (f[dis[u] ^ (1 << k)])
          ans[x] = max(ans[x], dep[u] + f[dis[u] ^ (1 << k)] - dep[x] * 2);
      }
    }
    for (int j = top[v]; j <= ed[v]; j++)
      f[dis[bel[j]]] = max(dep[bel[j]], f[dis[bel[j]]]);
  }
  if (!keep)
    for (int i = top[x]; i <= ed[x]; i++) f[dis[bel[i]]] = 0;
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    int u;
    char s;
    scanf("%d", &u);
    cin >> s;
    add(u, i + 1, 1 << (s - 'a'));
    add(i + 1, u, 1 << (s - 'a'));
  }
  dfs(1, 0);
  dfs1(1, 1);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
