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 N = 500005;
const int inf = 1000000009;
int rd() {
  char c = getchar();
  int t = 0, f = 1;
  while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar();
  while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
  return t * f;
}
void wt(int x) {
  if (x < 0) {
    putchar('-');
    wt(-x);
    return;
  }
  if (x > 9) wt(x / 10);
  putchar(x % 10 + 48);
  return;
}
int sz[N], L[N], R[N], v[N], dep[N], n;
int head[N], c[N], bk[N], son[N], F[1 << 22], Ans[N], cnt, Dfn;
struct Edge {
  int to, nxt;
} E[N];
void Link(int u, int v) {
  E[++cnt] = (Edge){v, head[u]};
  head[u] = cnt;
}
inline int Get() {
  char c = getchar();
  while (c < 97) c = getchar();
  return c;
}
void Dfs(int x) {
  sz[x] = 1, L[x] = ++Dfn, bk[Dfn] = x;
  for (int i = head[x]; i; i = E[i].nxt) {
    dep[E[i].to] = dep[x] + 1;
    v[E[i].to] = v[x] ^ c[E[i].to];
    Dfs(E[i].to), sz[x] += sz[E[i].to];
    if (sz[E[i].to] > sz[son[x]]) son[x] = E[i].to;
  }
  R[x] = Dfn;
  return;
}
void Solve(int x, int K) {
  for (int i = head[x]; i; i = E[i].nxt)
    if (E[i].to != son[x]) Solve(E[i].to, 0);
  if (son[x]) Solve(son[x], 1);
  Ans[x] = max(Ans[x], Ans[son[x]]);
  for (int y, i = head[x]; i; i = E[i].nxt)
    if ((y = E[i].to) != son[x]) {
      Ans[x] = max(Ans[x], Ans[y]);
      for (int j = ((int)L[y]); j <= ((int)R[y]); j++) {
        for (int k = ((int)0); k <= ((int)21); k++)
          Ans[x] =
              max(Ans[x], F[v[bk[j]] ^ (1 << k)] + dep[bk[j]] - dep[x] * 2);
        Ans[x] = max(Ans[x], F[v[bk[j]]] + dep[bk[j]] - dep[x] * 2);
      }
      for (int j = ((int)L[y]); j <= ((int)R[y]); j++)
        F[v[bk[j]]] = max(F[v[bk[j]]], dep[bk[j]]);
    }
  for (int k = ((int)0); k <= ((int)21); k++)
    Ans[x] = max(Ans[x], F[v[x] ^ (1 << k)] - dep[x]);
  Ans[x] = max(Ans[x], F[v[x]] - dep[x]);
  F[v[x]] = max(F[v[x]], dep[x]);
  if (!K)
    for (int j = ((int)L[x]); j <= ((int)R[x]); j++) F[v[bk[j]]] = -1e9;
}
int main() {
  n = rd();
  for (int i = ((int)2); i <= ((int)n); i++) {
    Link(rd(), i);
    c[i] = 1 << Get() - 97;
  }
  memset(F, -63, sizeof F);
  Dfs(1);
  Solve(1, 1);
  for (int i = ((int)1); i <= ((int)n); i++) wt(Ans[i]), putchar(32);
  return 0;
}
