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 S = 22;
const int N = 5e5 + 10;
const int NS = (1 << 22) + 10;
struct E {
  int v, w, nt;
} e[N << 1];
int n, cnt, tot, h[N], fa[N], sz[N], ans[N], dfn[N], pos[N];
int dep[N], dis[N], sub[N], son[N], vis[N], bin[30], dic[NS];
template <class T>
inline void in(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9';) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9';) x = x * 10 + ch - '0', ch = getchar();
  x = f ? -x : x;
}
inline void dfs(int u) {
  sz[u] = 1, pos[dfn[u] = ++cnt] = u;
  for (int v, i = h[u]; i; i = e[i].nt) {
    dis[v = e[i].v] = dis[u] ^ e[i].w;
    dep[v] = dep[u] + 1, dfs(v), sz[u] += sz[v];
    son[u] = sz[v] > sz[son[u]] ? v : son[u];
  }
  sub[u] = cnt;
}
inline void dfs2(int u) {
  for (int i = h[u]; i; i = e[i].nt)
    if (e[i].v != son[u]) dfs2(e[i].v), ans[u] = max(ans[u], ans[e[i].v]);
  if (son[u]) dfs2(son[u]), vis[son[u]] = 1, ans[u] = max(ans[u], ans[son[u]]);
  ans[u] = max(ans[u], dic[dis[u]] - dep[u]);
  for (int i = 0; i < S; ++i)
    ans[u] = max(ans[u], dic[dis[u] ^ bin[i]] - dep[u]);
  dic[dis[u]] = max(dic[dis[u]], dep[u]);
  for (int c, v, p = h[u]; p; p = e[p].nt) {
    if ((v = e[p].v) == son[u]) continue;
    for (int i = dfn[v]; i <= sub[v]; ++i) {
      if (dic[dis[c = pos[i]]])
        ans[u] = max(ans[u], dic[dis[c]] + dep[c] - 2 * dep[u]);
      for (int j = 0; j < S; ++j)
        if (dic[dis[c] ^ bin[j]])
          ans[u] = max(ans[u], dic[dis[c] ^ bin[j]] + dep[c] - 2 * dep[u]);
    }
    for (int i = dfn[v]; i <= sub[v]; ++i)
      dic[dis[pos[i]]] = max(dic[dis[pos[i]]], dep[pos[i]]);
  }
  if (u != son[fa[u]])
    for (int i = dfn[u]; i <= sub[u]; ++i) dic[dis[pos[i]]] = 0;
}
int main() {
  char ch;
  in(n), bin[0] = 1;
  for (int i = 1; i < 30; ++i) bin[i] = bin[i - 1] << 1;
  for (int i = 2; i <= n; ++i) {
    in(fa[i]), ch = getchar();
    for (; ch < 'a' || ch > 'v';) ch = getchar();
    e[++tot] = (E){i, bin[ch - 'a'], h[fa[i]]}, h[fa[i]] = tot;
  }
  dfs(1), son[0] = 1, dfs2(1);
  for (int i = 1; i <= n; ++i) printf("%d%c", ans[i], i == n ? '\n' : ' ');
  return 0;
}
