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 = 5e6 + 7, inf = 1 << 30;
int n, mx = 0, cnt = 0;
int path[N], ans[N];
int fir[N], nxt[N], val[N], to[N];
int dep[N], mxdep[N], siz[N], son[N];
inline void AddEdge(int u, int v, int w) {
  nxt[++cnt] = fir[u];
  fir[u] = cnt, to[cnt] = v, val[cnt] = w;
}
void dfs(int u) {
  siz[u] = 1;
  for (int i = fir[u]; i; i = nxt[i]) {
    int v = to[i], w = val[i];
    dep[v] = dep[u] + 1;
    path[v] = path[u] ^ (1 << w);
    dfs(v);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
}
void calc(int u, int root) {
  mx = max(mx, mxdep[path[u]] + dep[u] - 2 * dep[root]);
  for (int i = 0; i <= 21; i++)
    mx = max(mx, mxdep[(1 << i) ^ path[u]] + dep[u] - 2 * dep[root]);
  if ((path[u] ^ path[root]) == 0) mx = max(mx, dep[u] - dep[root]);
  for (int i = 0; i <= 21; i++) {
    if ((path[u] ^ path[root]) == (1 << i)) {
      mx = max(mx, dep[u] - dep[root]);
    }
  }
  for (int i = fir[u]; i; i = nxt[i]) {
    int v = to[i];
    calc(v, root);
  }
}
void modify(int u, bool del) {
  mxdep[path[u]] = (del ? -inf : max(mxdep[path[u]], dep[u]));
  for (int i = fir[u]; i; i = nxt[i]) {
    int v = to[i];
    modify(v, del);
  }
}
void dsu(int u, bool del) {
  for (int i = fir[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == son[u]) continue;
    dsu(v, 1);
  }
  if (son[u]) dsu(son[u], 0);
  mx = max(0, mxdep[path[u]] - dep[u]);
  for (int i = 0; i <= 21; i++)
    mx = max(mx, mxdep[(1 << i) ^ path[u]] - dep[u]);
  for (int i = fir[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == son[u]) continue;
    calc(v, u);
    modify(v, 0);
  }
  ans[u] = mx;
  if (del) {
    for (int i = fir[u]; i; i = nxt[i]) {
      int v = to[i];
      modify(v, 1);
    }
    mxdep[path[u]] = 0;
  } else
    mxdep[path[u]] = max(mxdep[path[u]], dep[u]);
}
void update(int u) {
  for (int i = fir[u]; i; i = nxt[i]) {
    int v = to[i];
    update(v);
    ans[u] = max(ans[u], ans[v]);
  }
}
int main() {
  scanf("%d", &n);
  for (int v = 2; v <= n; v++) {
    int u;
    char w;
    scanf("%d %c", &u, &w);
    AddEdge(u, v, (int)(w - 'a'));
  }
  for (int i = 0; i <= (1 << 22) - 1; i++) {
    mxdep[i] = -inf;
  }
  dfs(1);
  dsu(1, 0);
  update(1);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
