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;
int n, x, cur, h[maxn], nxt[maxn * 2], p[maxn * 2], fa[maxn], val[maxn],
    f[maxn * 10], ans[maxn], dep[maxn];
char c, w[maxn * 2];
void add_edge(int u, int v, char ch) {
  cur++;
  nxt[cur] = h[u];
  h[u] = cur;
  p[cur] = v;
  w[cur] = ch;
}
int siz[maxn], son[maxn];
void dfs1(int x) {
  siz[x] = 1;
  for (int j = h[x]; j; j = nxt[j])
    if (p[j] != fa[x]) {
      val[p[j]] = val[x] ^ (1 << (w[j] - 'a'));
      dep[p[j]] = dep[x] + 1;
      dfs1(p[j]);
      siz[x] += siz[p[j]];
      if (siz[p[j]] > siz[son[x]]) son[x] = p[j];
    }
}
void dfs3(int x, int rt) {
  if (f[val[x]]) ans[rt] = max(ans[rt], f[val[x]] + dep[x] - 2 * dep[rt]);
  for (int i = 0; i < 22; i++)
    if (f[val[x] ^ (1 << i)])
      ans[rt] = max(ans[rt], f[val[x] ^ (1 << i)] + dep[x] - 2 * dep[rt]);
  for (int j = h[x]; j; j = nxt[j])
    if (p[j] != fa[x]) dfs3(p[j], rt);
}
void dfs4(int x, int op) {
  if (op == -1)
    f[val[x]] = 0;
  else
    f[val[x]] = max(f[val[x]], dep[x]);
  for (int j = h[x]; j; j = nxt[j])
    if (p[j] != fa[x]) dfs4(p[j], op);
}
void dfs2(int x) {
  ans[x] = 0;
  for (int j = h[x]; j; j = nxt[j])
    if (p[j] != fa[x] && p[j] != son[x]) {
      dfs2(p[j]);
      ans[x] = max(ans[x], ans[p[j]]);
      dfs4(p[j], -1);
    }
  if (son[x]) {
    dfs2(son[x]);
    ans[x] = max(ans[x], ans[son[x]]);
    if (f[val[x]]) ans[x] = max(ans[x], f[val[x]] + dep[x] - 2 * dep[x]);
    for (int i = 0; i < 22; i++)
      if (f[val[x] ^ (1 << i)])
        ans[x] = max(ans[x], f[val[x] ^ (1 << i)] + dep[x] - 2 * dep[x]);
    f[val[x]] = max(f[val[x]], dep[x]);
    for (int j = h[x]; j; j = nxt[j])
      if (p[j] != fa[x] && p[j] != son[x]) dfs3(p[j], x), dfs4(p[j], 1);
  } else
    f[val[x]] = max(f[val[x]], dep[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++)
    scanf("%d %c", &x, &c), add_edge(i, x, c), add_edge(x, i, c), fa[i] = x;
  dfs1(1);
  dfs2(1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
