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;
using namespace std;
const int N = 500000;
int head[N + 50], num, a[N + 50], n, siz[N + 50], dep[N + 50], ans[N + 50],
    maxson[N + 50], s[N + 50], maxv, f[N * 20], inf;
struct Node {
  int next, to;
} edge[N + 50];
void Addedge(int u, int v) {
  edge[++num] = (Node){head[u], v};
  head[u] = num;
  return;
}
void Dfs1(int x, int fa) {
  siz[x] = 1;
  dep[x] = dep[fa] + 1;
  if (x != 1) s[x] = s[fa] ^ (1 << a[x]);
  for (int i = head[x]; i; i = edge[i].next) {
    int v = edge[i].to;
    Dfs1(v, x);
    siz[x] += siz[v];
    if (siz[v] > siz[maxson[x]]) maxson[x] = v;
  }
  return;
}
void Calc(int rt, int x) {
  int now = s[x];
  maxv = max(maxv, f[now] + dep[x] - 2 * dep[rt]);
  if ((s[x] ^ s[rt]) == 0) maxv = max(maxv, dep[x] - dep[rt]);
  for (int i = 0; i < 22; i++) {
    now = (1 << i) ^ s[x];
    maxv = max(maxv, f[now] + dep[x] - 2 * dep[rt]);
    if ((s[x] ^ s[rt]) == (1 << i)) maxv = max(maxv, dep[x] - dep[rt]);
  }
  for (int i = head[x]; i; i = edge[i].next) {
    int v = edge[i].to;
    Calc(rt, v);
  }
  return;
}
void Change(int x, int k) {
  if (k)
    f[s[x]] = max(f[s[x]], dep[x]);
  else
    f[s[x]] = inf;
  for (int i = head[x]; i; i = edge[i].next) Change(edge[i].to, k);
  return;
}
void Dfs2(int x, int remain) {
  for (int i = head[x]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == maxson[x]) continue;
    Dfs2(v, 0);
  }
  if (maxson[x]) Dfs2(maxson[x], 1);
  maxv = 0;
  int now = s[x];
  maxv = max(maxv, f[now] - dep[x]);
  for (int i = 0; i < 22; i++) {
    now = (1 << i) ^ s[x];
    maxv = max(maxv, f[now] - dep[x]);
  }
  for (int i = head[x]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == maxson[x]) continue;
    Calc(x, v);
    Change(v, 1);
  }
  ans[x] = maxv;
  if (!remain) {
    for (int i = head[x]; i; i = edge[i].next) Change(edge[i].to, 0);
    f[s[x]] = inf;
  } else
    f[s[x]] = max(f[s[x]], dep[x]);
  return;
}
void Erase(int x) {
  for (int i = head[x]; i; i = edge[i].next) {
    int v = edge[i].to;
    Erase(v);
    ans[x] = max(ans[x], ans[v]);
  }
  return;
}
int main() {
  scanf("%d", &n);
  char tmp;
  for (int i = 2, fa; i <= n; i++) {
    scanf("%d", &fa);
    cin >> tmp;
    Addedge(fa, i);
    a[i] = tmp - 'a';
  }
  Dfs1(1, 0);
  memset(f, 128, sizeof(f));
  inf = f[0];
  Dfs2(1, 0);
  Erase(1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
