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 inf = 1e9;
int read() {
  int x = 0, p = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') p = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return p ? x : -x;
}
int n, hd[500010], cnt, siz[500010], son[500010], dep[500010], val[500010];
struct Edge {
  int nxt, to, w;
} e[500010];
inline void add(int u, int v, int c) {
  e[++cnt] = (Edge){hd[u], v, 1 << c}, hd[u] = cnt;
}
void dfs(int u) {
  siz[u] = 1;
  for (int i = hd[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    dep[v] = dep[u] + 1, val[v] = val[u] ^ e[i].w;
    dfs(v), siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
}
int buk[(1 << 22) + 10], ans[500010], mx, root;
void calc(int u) {
  int sta, ex = dep[root] << 1;
  if (buk[val[u]]) mx = max(mx, dep[u] + buk[val[u]] - ex);
  if (val[u] == val[root]) mx = max(mx, dep[u] - dep[root]);
  for (int i = 0; i ^ 22; ++i) {
    if (buk[sta = (1 << i) ^ val[u]]) mx = max(mx, dep[u] + buk[sta] - ex);
    if ((val[u] ^ val[root]) == (1 << i)) mx = max(mx, dep[u] - dep[root]);
  }
  for (int i = hd[u]; i; i = e[i].nxt) calc(e[i].to);
}
void update(int u, int tag) {
  if (tag)
    buk[val[u]] = max(buk[val[u]], dep[u]);
  else
    buk[val[u]] = 0;
  for (int i = hd[u]; i; i = e[i].nxt) update(e[i].to, tag);
}
void heavy(int u) {
  int sta;
  if (buk[val[u]]) mx = max(mx, buk[val[u]] - dep[u]);
  for (int i = 0; i ^ 22; ++i)
    if (buk[sta = (1 << i) ^ val[u]]) mx = max(mx, buk[sta] - dep[u]);
}
void dfs(int u, int keep) {
  for (int i = hd[u]; i; i = e[i].nxt)
    if (e[i].to ^ son[u]) dfs(e[i].to, 0);
  if (son[u]) dfs(son[u], 1);
  for (int i = hd[u]; i; i = e[i].nxt) mx = max(mx, ans[e[i].to]);
  heavy(u);
  for (int i = hd[u]; i; i = e[i].nxt)
    if (e[i].to ^ son[u]) root = u, calc(e[i].to), update(e[i].to, 1);
  ans[u] = mx;
  if (!keep)
    update(u, 0), mx = 0;
  else
    buk[val[u]] = max(buk[val[u]], dep[u]);
}
int main() {
  n = read();
  int p;
  char ch;
  for (int i = 2; i <= n; ++i) p = read(), ch = getchar(), add(p, i, ch - 'a');
  dfs(1), dfs(1, 1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  putchar('\n');
}
