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>
const int MAXN = 500007;
int size[MAXN], son[MAXN], ans[MAXN], f[1 << 22], depth[MAXN], Xorval[MAXN],
    dfn[MAXN], low[MAXN], time_stamp, id[MAXN];
struct Edge {
  int to, nextEdge, val;
} e[MAXN << 1];
int cntEdge, head[MAXN];
inline void insert(int u, int v, int val) {
  ++cntEdge;
  e[cntEdge].to = v, e[cntEdge].nextEdge = head[u], head[u] = cntEdge,
  e[cntEdge].val = val;
  return;
}
void pre_dfs(int u, int fa) {
  dfn[u] = ++time_stamp;
  id[time_stamp] = u;
  size[u] = 1;
  for (int it = head[u]; it != 0; it = e[it].nextEdge) {
    int v = e[it].to;
    if (v != fa) {
      Xorval[v] = Xorval[u] ^ e[it].val;
      depth[v] = depth[u] + 1;
      pre_dfs(v, u);
      size[u] += size[v];
      if (size[v] > size[son[u]]) son[u] = v;
    }
  }
  low[u] = time_stamp;
  return;
}
void dsu(int u, int fa, int keep) {
  for (int it = head[u]; it != 0; it = e[it].nextEdge) {
    int v = e[it].to;
    if (v == fa || v == son[u]) continue;
    dsu(v, u, 0);
    ans[u] = std::max(ans[u], ans[v]);
  }
  if (son[u]) dsu(son[u], u, 1), ans[u] = std::max(ans[u], ans[son[u]]);
  if (f[Xorval[u]]) ans[u] = std::max(ans[u], f[Xorval[u]] - depth[u]);
  for (int i = 0; i < 22; ++i)
    if (f[Xorval[u] ^ (1 << i)])
      ans[u] = std::max(ans[u], f[Xorval[u] ^ (1 << i)] - depth[u]);
  f[Xorval[u]] = std::max(f[Xorval[u]], depth[u]);
  for (int it = head[u]; it != 0; it = e[it].nextEdge) {
    int v = e[it].to;
    if (v == fa || v == son[u]) continue;
    for (int i = dfn[v]; i <= low[v]; ++i) {
      if (f[Xorval[id[i]]])
        ans[u] =
            std::max(ans[u], f[Xorval[id[i]]] + depth[id[i]] - (depth[u] << 1));
      for (int j = 0; j < 22; ++j)
        if (f[Xorval[id[i]] ^ (1 << j)])
          ans[u] = std::max(ans[u], f[Xorval[id[i]] ^ (1 << j)] + depth[id[i]] -
                                        (depth[u] << 1));
    }
    for (int i = dfn[v]; i <= low[v]; ++i)
      f[Xorval[id[i]]] = std::max(f[Xorval[id[i]]], depth[id[i]]);
  }
  if (!keep)
    for (int i = dfn[u]; i <= low[u]; ++i) f[Xorval[id[i]]] = 0;
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int p;
    char s[2];
    scanf("%d%s", &p, s);
    insert(p, i, 1 << (s[0] - 'a'));
    insert(i, p, 1 << (s[0] - 'a'));
  }
  depth[1] = 1;
  pre_dfs(1, -1);
  dsu(1, -1, 1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
