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 = 5e5 + 5;
const int maxs = 1 << 22;
const int INF = 0x3f3f3f3f;
int n, cnt;
int head[maxn];
int siz[maxn], son[maxn], dep[maxn];
int max_dep[maxs], dis[maxn];
int ans[maxn];
struct Edge {
  int to, next;
} e[maxn];
void Aedge(int x, int y) {
  e[++cnt].to = y;
  e[cnt].next = head[x];
  head[x] = cnt;
}
void dfs1(int x) {
  siz[x] = 1;
  for (int i = head[x]; i; i = e[i].next) {
    const register int y = e[i].to;
    dis[y] ^= dis[x], dep[y] = dep[x] + 1;
    dfs1(y);
    siz[x] += siz[y];
    if (!son[x] || siz[y] > siz[son[x]]) son[x] = y;
  }
}
void upd_ans(int rt, int x) {
  ans[rt] = max(ans[rt], max_dep[dis[x]] + dep[x] - dep[rt] * 2);
  for (int i = 0; i <= 21; ++i)
    ans[rt] = max(ans[rt], max_dep[dis[x] ^ (1 << i)] + dep[x] - dep[rt] * 2);
  for (int i = head[x]; i; i = e[i].next) upd_ans(rt, e[i].to);
}
void upd_max_dep(int x) {
  max_dep[dis[x]] = max(max_dep[dis[x]], dep[x]);
  for (int i = head[x]; i; i = e[i].next) upd_max_dep(e[i].to);
}
void cle(int x) {
  max_dep[dis[x]] = -INF;
  for (int i = head[x]; i; i = e[i].next) cle(e[i].to);
}
void dfs(int x, int op) {
  for (int i = head[x]; i; i = e[i].next) {
    const register int y = e[i].to;
    if (y != son[x]) dfs(y, 0), ans[x] = max(ans[x], ans[y]);
  }
  if (son[x]) dfs(son[x], 1), ans[x] = max(ans[x], ans[son[x]]);
  for (int i = head[x]; i; i = e[i].next) {
    const register int y = e[i].to;
    if (y != son[x]) upd_ans(x, y), upd_max_dep(y);
  }
  ans[x] = max(ans[x], max_dep[dis[x]] - dep[x]);
  for (int i = 0; i <= 21; ++i)
    ans[x] = max(ans[x], max_dep[dis[x] ^ (1 << i)] - dep[x]);
  max_dep[dis[x]] = max(max_dep[dis[x]], dep[x]);
  if (!op) cle(x);
}
int main() {
  memset(max_dep, -INF, sizeof max_dep);
  scanf("%d", &n);
  for (int i = 2, x; i <= n; ++i) {
    char ss;
    scanf("%d %c", &x, &ss);
    Aedge(x, i), dis[i] = 1 << (ss - 'a');
  }
  dfs1(1);
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
