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 maxn = 500010;
const int maxm = 500010;
int Max(int a, int b) { return a > b ? a : b; }
int Min(int a, int b) { return a < b ? a : b; }
int n, tol, head[maxn];
struct edge {
  int to, next, cost;
} es[maxm];
int dfn[maxn], low[maxn], id[maxn], tim;
int sizes[maxn], wson[maxn], dep[maxn], Xor[maxn];
int ans[maxn], f[1 << 22];
void addedge(int u, int v, int w) {
  es[tol].to = v;
  es[tol].cost = w;
  es[tol].next = head[u];
  head[u] = tol++;
}
void dfs1(int u) {
  dfn[u] = ++tim;
  id[tim] = u;
  sizes[u] = 1;
  for (int i = head[u]; i != -1; i = es[i].next) {
    int v = es[i].to;
    dep[v] = dep[u] + 1;
    Xor[v] = Xor[u] ^ es[i].cost;
    dfs1(v);
    sizes[u] += sizes[v];
    if (sizes[v] > sizes[wson[u]]) wson[u] = v;
  }
  low[u] = tim;
}
void dfs2(int u, bool used) {
  for (int i = head[u]; i != -1; i = es[i].next) {
    int v = es[i].to;
    if (v == wson[u]) continue;
    dfs2(v, 0);
    ans[u] = Max(ans[u], ans[v]);
  }
  if (wson[u]) dfs2(wson[u], 1), ans[u] = Max(ans[u], ans[wson[u]]);
  if (f[Xor[u]]) ans[u] = Max(ans[u], f[Xor[u]] - dep[u]);
  for (int i = 0; i < 22; i++)
    if (f[Xor[u] ^ (1 << i)])
      ans[u] = Max(ans[u], f[Xor[u] ^ (1 << i)] - dep[u]);
  f[Xor[u]] = Max(f[Xor[u]], dep[u]);
  for (int i = head[u]; i != -1; i = es[i].next) {
    int v = es[i].to;
    if (v != wson[u]) {
      for (int j = dfn[v]; j <= low[v]; j++) {
        if (f[Xor[id[j]]])
          ans[u] = Max(ans[u], f[Xor[id[j]]] + dep[id[j]] - 2 * dep[u]);
        for (int k = 0; k < 22; k++)
          if (f[Xor[id[j]] ^ (1 << k)])
            ans[u] =
                Max(ans[u], f[Xor[id[j]] ^ (1 << k)] + dep[id[j]] - 2 * dep[u]);
      }
      for (int j = dfn[v]; j <= low[v]; j++)
        f[Xor[id[j]]] = Max(f[Xor[id[j]]], dep[id[j]]);
    }
  }
  if (!used)
    for (int i = dfn[u]; i <= low[u]; i++) f[Xor[id[i]]] = 0;
}
int main() {
  memset(f, 0, sizeof(f));
  memset(ans, 0, sizeof(ans));
  tol = 0;
  Xor[1] = 0;
  sizes[0] = 0;
  tim = 0;
  memset(head, -1, sizeof(head));
  memset(wson, 0, sizeof(wson));
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int f;
    char s[5];
    scanf("%d%s", &f, s);
    addedge(f, i, 1 << (s[0] - 'a'));
  }
  dep[1] = 1;
  dfs1(1);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
