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;
int c = 1, son[N], dpt[N], n;
struct node {
  int y, z, nxt;
} e[N];
int len[1 << 22], ans[N], rfn[N], ed[N];
int tot, h[N], siz[N], d[N], v[N], dfn[N];
void add(int x, int y, int z) {
  e[++c] = (node){y, z, h[x]};
  h[x] = c;
}
void dfs(int x, int fa) {
  siz[x] = 1;
  for (int i = h[x], y; i; i = e[i].nxt)
    if ((y = e[i].y) != fa) {
      d[y] = d[x] + 1;
      v[y] = v[x] ^ (1 << e[i].z);
      dfs(y, x);
      if (siz[y] > siz[son[x]]) son[x] = y;
      siz[x] += siz[y];
    }
  return;
}
int get(int x) {
  int ans = 0;
  if (len[v[x]]) ans = d[x] + len[v[x]];
  for (int i = 0; i < 22; i++)
    if (len[v[x] ^ (1 << i)]) ans = max(ans, d[x] + len[v[x] ^ (1 << i)]);
  return ans;
}
void dsu(int x, int tp) {
  dfn[rfn[x] = ++tot] = x;
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].y != son[x])
      dsu(e[i].y, e[i].y), ans[x] = max(ans[x], ans[e[i].y]);
  int mid = tot;
  if (son[x]) dsu(son[x], tp), ans[x] = max(ans[x], ans[son[x]]);
  ed[x] = tot;
  for (int i = rfn[x] + 1; i <= mid; i = ed[dfn[i]] + 1) {
    for (int j = i; j <= ed[dfn[i]]; j++)
      ans[x] = max(ans[x], get(dfn[j]) - 2 * d[x]);
    for (int j = i; j <= ed[dfn[i]]; j++)
      len[v[dfn[j]]] = max(len[v[dfn[j]]], d[dfn[j]]);
  }
  ans[x] = max(ans[x], get(x) - d[x] * 2);
  len[v[x]] = max(len[v[x]], d[x]);
  if (x == tp)
    for (int i = rfn[x]; i <= ed[x]; i++) len[v[dfn[i]]] = 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 2, x; i <= n; i++) {
    scanf("%d", &x);
    char c = getchar();
    while (c < 'a' || c > 'v') c = getchar();
    add(x, i, c - 'a');
  }
  d[0] = -1;
  dfs(1, 0);
  dsu(1, 1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return puts(""), 0;
}
