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;
struct Q {
  int Next, To, Dis;
} Edge[500005];
int From[500005], Sum_Edge;
namespace BAsis {
inline int Read() {
  char Ch = getchar();
  while (Ch < 48 || Ch > 57) Ch = getchar();
  int x = Ch - 48;
  Ch = getchar();
  while (Ch >= 48 && Ch <= 57) x = (x * 10) + (Ch - 48), Ch = getchar();
  return x;
}
inline int Max(const int &x, const int &y) { return x > y ? x : y; }
inline int Min(const int &x, const int &y) { return x < y ? x : y; }
inline void Swap(int &x, int &y) {
  register int p = x;
  x = y;
  y = p;
}
inline void Add(const int &x, const int &y, const int &d) {
  Edge[++Sum_Edge] = (Q){From[x], y, d};
  From[x] = Sum_Edge;
}
}  // namespace BAsis
using namespace BAsis;
int Size[500005], Son[500005], Dep[500005], Dis[500005], Ans[500005],
    ff[(1 << 22) + 5];
int n, m, CMax, D;
void Dfs1(const int &u, const int &f) {
  Size[u] = 1;
  Dep[u] = Dep[f] + 1;
  for (int e = From[u]; e; e = Edge[e].Next) {
    int v = Edge[e].To;
    if (v == f) continue;
    Dis[v] = Dis[u] ^ (1 << Edge[e].Dis);
    Dfs1(v, u);
    Size[u] += Size[v];
    if (Size[v] > Size[Son[u]]) Son[u] = v;
  }
}
void Insert(const int &u) {
  if (ff[Dis[u]]) CMax = Max(CMax, Dep[u] + ff[Dis[u]] - D);
  for (int i = (0); i <= (21); ++i)
    if (ff[(1 << i) ^ Dis[u]])
      CMax = Max(CMax, Dep[u] + ff[(1 << i) ^ Dis[u]] - D);
}
void Update(const int &u) {
  ff[Dis[u]] = Max(ff[Dis[u]], Dep[u]);
  for (int e = From[u]; e; e = Edge[e].Next) Update(Edge[e].To);
}
void Calc(const int &u) {
  Insert(u);
  for (int e = From[u]; e; e = Edge[e].Next) Calc(Edge[e].To);
}
void Clear(const int &u) {
  ff[Dis[u]] = 0;
  for (int e = From[u]; e; e = Edge[e].Next) Clear(Edge[e].To);
}
void Solve(const int &u, const bool &flag = 0) {
  for (int e = From[u]; e; e = Edge[e].Next) {
    int v = Edge[e].To;
    if (v == Son[u]) continue;
    Solve(v);
  }
  if (Son[u]) Solve(Son[u], 1);
  D = Dep[u] * 2;
  for (int e = From[u]; e; e = Edge[e].Next) CMax = Max(CMax, Ans[Edge[e].To]);
  for (int e = From[u]; e; e = Edge[e].Next) {
    int v = Edge[e].To;
    if (v == Son[u]) continue;
    Calc(v);
    Update(v);
  }
  Insert(u);
  ff[Dis[u]] = Max(ff[Dis[u]], Dep[u]);
  Ans[u] = CMax;
  if (!flag) Clear(u), CMax = 0;
}
void Work() {
  int x;
  char opt[5];
  n = Read();
  for (int i = (2); i <= (n); ++i) {
    x = Read();
    scanf("%s", opt);
    Add(x, i, opt[0] - 'a');
  }
  Dfs1(1, 0);
  Solve(1, 1);
  for (int i = (1); i <= (n); ++i) printf("%d ", Ans[i]);
}
signed main() {
  Work();
  return 0;
}
