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 maxn = 500010;
template <typename elemType>
inline void Read(elemType &T) {
  elemType X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  T = (w ? -X : X);
}
struct Graph {
  struct edge {
    int Next, to, w;
  };
  edge G[maxn << 1];
  int head[maxn];
  int cnt;
  Graph() : cnt(2) {}
  void clear(int node_num = 0) {
    cnt = 2;
    if (node_num == 0)
      memset(head, 0, sizeof(head));
    else
      fill(head, head + node_num + 5, 0);
  }
  void add_edge(int u, int v, int w) {
    G[cnt].w = w;
    G[cnt].to = v;
    G[cnt].Next = head[u];
    head[u] = cnt++;
  }
};
Graph G;
int cnt[8400000], Size[maxn], Hson[maxn], ans[maxn], dis[maxn];
int L[maxn], R[maxn], id[maxn], deep[maxn];
int ok[23];
int N, Son, Res, Index;
void DFS_Init(int u, int fa) {
  Size[u] = 1;
  id[++Index] = u;
  L[u] = Index;
  deep[u] = deep[fa] + 1;
  for (int i = G.head[u]; i; i = G.G[i].Next) {
    int v = G.G[i].to;
    if (v == fa) continue;
    dis[v] = dis[u] ^ G.G[i].w;
    DFS_Init(v, u);
    Size[u] += Size[v];
    if (Size[v] > Size[Hson[u]]) Hson[u] = v;
  }
  R[u] = Index;
}
inline void Calc(int u, int v) {
  for (int x = L[v]; x <= R[v]; ++x)
    for (int j = 0; j < 23; ++j)
      if (cnt[dis[id[x]] ^ ok[j]])
        ans[u] = max(ans[u],
                     deep[id[x]] - deep[u] + cnt[dis[id[x]] ^ ok[j]] - deep[u]);
}
inline void CalcInOneSubTree(int u, int v) {
  for (int j = 0; j < 23; ++j)
    if (cnt[dis[u] ^ ok[j]])
      ans[u] = max(ans[u], cnt[dis[u] ^ ok[j]] - deep[u]);
}
void DFS(int u, int fa, bool keep) {
  for (int i = G.head[u]; i; i = G.G[i].Next) {
    int v = G.G[i].to;
    if (v == fa || v == Hson[u]) continue;
    DFS(v, u, false);
    ans[u] = max(ans[u], ans[v]);
  }
  if (Hson[u]) {
    DFS(Hson[u], u, true);
    ans[u] = max(ans[u], ans[Hson[u]]);
  }
  cnt[dis[u]] = max(cnt[dis[u]], deep[u]);
  if (Hson[u]) CalcInOneSubTree(u, Hson[u]);
  for (int i = G.head[u]; i; i = G.G[i].Next) {
    int v = G.G[i].to;
    if (v == fa || v == Hson[u]) continue;
    Calc(u, v);
    CalcInOneSubTree(u, v);
    for (int x = L[v]; x <= R[v]; ++x)
      cnt[dis[id[x]]] = max(cnt[dis[id[x]]], deep[id[x]]);
  }
  if (!keep) {
    for (int x = L[u]; x <= R[u]; ++x) cnt[dis[id[x]]] = 0;
  }
}
int main() {
  for (int i = 0; i < 22; ++i) ok[i + 1] = 1 << i;
  Read(N);
  for (int u = 2; u <= N; ++u) {
    int v, w;
    char c;
    Read(v);
    scanf("%c", &c);
    w = 1 << (c - 'a');
    G.add_edge(u, v, w);
    G.add_edge(v, u, w);
  }
  DFS_Init(1, 0);
  DFS(1, 0, true);
  for (int u = 1; u <= N; ++u) {
    printf("%d", ans[u]);
    if (u < N) printf(" ");
  }
  return 0;
}
