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;
void file(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
template <typename Tp>
void read(Tp &x) {
  x = 0;
  int fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= fh;
}
struct Edge {
  int f, t, w, nxt;
} edge[500005 << 1];
int head[500005], etot = 1;
void add_edge(int f, int t, int w) {
  edge[++etot] = (Edge){f, t, w, head[f]};
  head[f] = etot;
}
int n, m;
int fa[500005], son[500005], siz[500005], dep[500005];
int prew[500005];
void dfs1(int x) {
  siz[x] = 1;
  dep[x] = dep[fa[x]] + 1;
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    prew[y] = (prew[x] ^ (1 << edge[i].w));
    dfs1(y);
    siz[x] += siz[y];
    if (siz[son[x]] < siz[y]) son[x] = y;
  }
}
int f[5000005];
int ans[500005];
void add(int x) {
  f[prew[x]] = max(f[prew[x]], dep[x]);
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    add(y);
  }
}
void upd_ans(int x, int lc) {
  ans[lc] = max(ans[lc], dep[x] + f[prew[x]] - 2 * dep[lc]);
  for (int i = 0; i < 22; i++) {
    ans[lc] = max(ans[lc], dep[x] + f[prew[x] ^ (1 << i)] - 2 * dep[lc]);
  }
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    upd_ans(y, lc);
  }
}
void del(int x) {
  f[prew[x]] = -0x3f3f3f3f;
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    del(y);
  }
}
void dfs2(int x, int typ) {
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    if (y == son[x]) continue;
    dfs2(y, 0);
  }
  if (son[x]) dfs2(son[x], 1);
  ans[x] = max(ans[x], f[prew[x]] - dep[x]);
  for (int i = 0; i < 22; i++) {
    ans[x] = max(ans[x], f[prew[x] ^ (1 << i)] - dep[x]);
  }
  f[prew[x]] = max(f[prew[x]], dep[x]);
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    if (y == son[x]) continue;
    upd_ans(y, x);
    add(y);
  }
  if (!typ) del(x);
  for (int i = head[x]; i; i = edge[i].nxt) {
    int y = edge[i].t;
    ans[x] = max(ans[x], ans[y]);
  }
}
signed main() {
  memset(f, 0xc0, sizeof(f));
  char ch;
  read(n);
  for (int i = 2; i <= n; i++) {
    scanf("%d %c", &fa[i], &ch);
    add_edge(fa[i], i, ch - 'a');
  }
  dfs1(1);
  dfs2(1, 1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
