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 read() {
  int f = 1, w = 0;
  char x = 0;
  while (x < '0' || x > '9') {
    if (x == '-') f = -1;
    x = getchar();
  }
  while (x != EOF && x >= '0' && x <= '9') {
    w = (w << 3) + (w << 1) + (x ^ 48);
    x = getchar();
  }
  return w * f;
}
const int N = 500010;
int num_edge, n, Tim, Id[N];
int head[N], Dep[N], Xor[N], f[1 << 22], End[N];
int Vis[N], Siz[N], Max[N], ans[N], Dfn[N];
struct Edge {
  int next, to, dis;
} edge[N];
inline void Add(int from, int to, int dis) {
  edge[++num_edge].next = head[from];
  edge[num_edge].dis = dis;
  edge[num_edge].to = to;
  head[from] = num_edge;
}
inline void Dfs_For_Pre(int pos, int fth, int dis) {
  Dfn[pos] = ++Tim, Id[Dfn[pos]] = pos;
  Siz[pos] = 1;
  Dep[pos] = Dep[fth] + 1;
  Xor[pos] = Xor[fth] ^ dis;
  for (int i = head[pos]; i; i = edge[i].next) {
    Dfs_For_Pre(edge[i].to, pos, edge[i].dis);
    Siz[pos] += Siz[edge[i].to];
    if (Siz[Max[pos]] < Siz[edge[i].to]) Max[pos] = edge[i].to;
  }
  End[pos] = Tim;
}
inline void Dsu_On_Tree(int pos, int Jud) {
  for (int i = head[pos]; i; i = edge[i].next)
    if (edge[i].to != Max[pos])
      Dsu_On_Tree(edge[i].to, 0), ans[pos] = max(ans[pos], ans[edge[i].to]);
  if (Max[pos])
    Dsu_On_Tree(Max[pos], 1), ans[pos] = max(ans[pos], ans[Max[pos]]);
  if (f[Xor[pos]]) ans[pos] = max(ans[pos], f[Xor[pos]] - Dep[pos]);
  for (int i = 0; i < 22; i++)
    if (f[Xor[pos] ^ (1 << i)])
      ans[pos] = max(ans[pos], f[Xor[pos] ^ (1 << i)] - Dep[pos]);
  f[Xor[pos]] = max(f[Xor[pos]], Dep[pos]);
  for (int i = head[pos]; i; i = edge[i].next)
    if (edge[i].to != Max[pos]) {
      for (int j = Dfn[edge[i].to]; j <= End[edge[i].to]; j++) {
        if (f[Xor[Id[j]]])
          ans[pos] =
              max(ans[pos], f[Xor[Id[j]]] + Dep[Id[j]] - (Dep[pos] << 1));
        for (int k = 0; k < 22; k++)
          if (f[Xor[Id[j]] ^ (1 << k)])
            ans[pos] = max(ans[pos], f[Xor[Id[j]] ^ (1 << k)] + Dep[Id[j]] -
                                         (Dep[pos] << 1));
      }
      for (int j = Dfn[edge[i].to]; j <= End[edge[i].to]; j++)
        f[Xor[Id[j]]] = max(f[Xor[Id[j]]], Dep[Id[j]]);
    }
  if (!Jud)
    for (int j = Dfn[pos]; j <= End[pos]; j++) f[Xor[Id[j]]] = 0;
}
int main() {
  char c;
  n = read();
  for (int i = 2, x; i <= n; i++)
    x = read(), c = getchar(), Add(x, i, 1 << (c - 'a'));
  Dfs_For_Pre(1, 0, 0);
  Dsu_On_Tree(1, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
