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;
int n, Mx, Mn;
int head[maxn], size;
int son[maxn], sz[maxn], ans[maxn];
int sum[maxn], dep[maxn], dep_sum[maxn * 10];
char s[5];
struct node {
  int v, nxt, w;
} e[maxn];
void add(int u, int v, int w) {
  e[++size].v = v;
  e[size].w = w;
  e[size].nxt = head[u];
  head[u] = size;
}
void dfs1(int u) {
  sz[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v, w = e[i].w;
    sum[v] = sum[u] ^ w;
    dep[v] = dep[u] + 1;
    dfs1(v);
    sz[u] += sz[v];
    if (sz[son[u]] < sz[v]) son[u] = v;
  }
}
void Count(int u, int rt) {
  Mx = max(Mx, dep_sum[sum[u]] + dep[u] - 2 * dep[rt]);
  for (int i = 0; i < 22; ++i)
    Mx = max(Mx, dep_sum[(1 << i) ^ sum[u]] + dep[u] - 2 * dep[rt]);
  if (!(sum[u] ^ sum[rt])) Mx = max(Mx, dep[u] - dep[rt]);
  for (int i = 0; i < 22; i++)
    if ((sum[u] ^ sum[rt]) == (1 << i)) Mx = max(Mx, dep[u] - dep[rt]);
  for (int i = head[u]; i; i = e[i].nxt) Count(e[i].v, rt);
}
void update(int u, bool op) {
  dep_sum[sum[u]] = op ? max(dep_sum[sum[u]], dep[u]) : Mn;
  for (int i = head[u]; i; i = e[i].nxt) update(e[i].v, op);
}
void dfs2(int u, bool op) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (son[u] != v) dfs2(v, 0);
  }
  if (son[u]) dfs2(son[u], 1);
  Mx = max(0, dep_sum[sum[u]] - dep[u]);
  for (int i = 0; i < 22; ++i)
    Mx = max(Mx, dep_sum[(1 << i) ^ sum[u]] - dep[u]);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == son[u]) continue;
    Count(v, u);
    update(v, 1);
  }
  ans[u] = Mx;
  if (op)
    dep_sum[sum[u]] = max(dep[u], dep_sum[sum[u]]);
  else {
    for (int i = head[u]; i; i = e[i].nxt) update(e[i].v, 0);
    dep_sum[sum[u]] = 0;
  }
}
void merge(int u) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    merge(v);
    ans[u] = max(ans[u], ans[v]);
  }
}
int main() {
  memset(dep_sum, ~0x3f, sizeof(dep_sum));
  Mn = ~0x3f3f3f3f;
  scanf("%d", &n);
  for (int i = 2, a; i <= n; ++i) {
    scanf("%d%s", &a, s);
    add(a, i, 1 << (s[0] - 'a'));
  }
  dfs1(1);
  dfs2(1, 0);
  merge(1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
