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;
inline int gi() {
  int f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 500010;
int n, dep[N], siz[N], son[N], front[N], cnt, dfn[N], Time, low[N], dis[N],
    id[N], ans[N], mx, f[1 << 22];
struct node {
  int to, nxt, w;
} e[N];
void Add(int u, int v, int w) {
  e[++cnt] = (node){v, front[u], w};
  front[u] = cnt;
}
void dfs(int u, int ff) {
  id[dfn[u] = ++Time] = u;
  siz[u] = 1;
  dep[u] = dep[ff] + 1;
  for (int i = front[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    dis[v] = dis[u] ^ e[i].w;
    dfs(v, u);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
  low[u] = Time;
}
void dfs(int u, int ff, int kp) {
  for (int i = front[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == son[u]) continue;
    dfs(v, u, 0);
    ans[u] = max(ans[u], ans[v]);
  }
  if (son[u]) dfs(son[u], u, 1), ans[u] = max(ans[u], ans[son[u]]);
  if (f[dis[u]]) ans[u] = max(ans[u], f[dis[u]] - dep[u]);
  for (int i = 0; i < 22; i++)
    if (f[dis[u] ^ (1 << i)])
      ans[u] = max(ans[u], f[dis[u] ^ (1 << i)] - dep[u]);
  f[dis[u]] = max(f[dis[u]], dep[u]);
  for (int E = front[u]; E; E = e[E].nxt) {
    int v = e[E].to;
    if (v == son[u]) continue;
    for (int i = dfn[v]; i <= low[v]; i++) {
      if (f[dis[id[i]]])
        ans[u] = max(ans[u], f[dis[id[i]]] + dep[id[i]] - (dep[u] << 1));
      for (int j = 0; j < 22; j++)
        if (f[dis[id[i]] ^ (1 << j)])
          ans[u] = max(ans[u],
                       f[dis[id[i]] ^ (1 << j)] + dep[id[i]] - (dep[u] << 1));
    }
    for (int i = dfn[v]; i <= low[v]; i++)
      f[dis[id[i]]] = max(f[dis[id[i]]], dep[id[i]]);
  }
  if (!kp)
    for (int i = dfn[u]; i <= low[u]; i++) f[dis[id[i]]] = 0;
}
int main() {
  n = gi();
  for (int i = 2; i <= n; i++) {
    int F = gi();
    char ch = getchar();
    while (ch < 'a' || ch > 'v') ch = getchar();
    Add(F, i, 1 << (ch - 'a'));
  }
  dfs(1, 1);
  dfs(1, 1, 1);
  for (int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n' : ' ');
  return 0;
}
