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 void Rd(int &res) {
  char c;
  res = 0;
  while (c = getchar(), c < '0')
    ;
  do {
    res = (res << 1) + (res << 3) + (c ^ 48);
  } while (c = getchar(), c >= '0');
}
void Pn(int x) {
  if (!x) return;
  Pn(x / 10);
  putchar(x % 10 ^ 48);
}
void Pf(int x) {
  if (!x) putchar('0');
  Pn(x);
}
const int M = 500005;
const int Mx = (1 << 22) + 5;
struct Node {
  int to;
  char c;
  int nxt;
} Edge[M];
int Head[M], tot;
inline void Addedge(int a, int b, char c) {
  Edge[tot] = (Node){b, c, Head[a]};
  Head[a] = tot++;
}
int sz[M], son[M], S[M], depth[M], Ans[M];
int Mp[Mx];
void dfs(int x, int f) {
  sz[x] = 1;
  for (int i = Head[x]; ~i; i = Edge[i].nxt) {
    int to = Edge[i].to, c = Edge[i].c;
    if (to == f) continue;
    depth[to] = depth[x] + 1;
    S[to] = S[x] ^ (1 << (c - 'a'));
    dfs(to, x);
    sz[x] += sz[to];
    if (sz[to] > sz[son[x]]) son[x] = to;
  }
}
void add(int x) {
  if (depth[x] > Mp[S[x]]) Mp[S[x]] = depth[x];
}
void calc(int x, int lca) {
  for (int i = 0; i <= 'v' - 'a'; i++)
    if (~Mp[S[x] ^ (1 << i)])
      Ans[lca] = max(Ans[lca], Mp[S[x] ^ (1 << i)] + depth[x] - 2 * depth[lca]);
  if (~Mp[S[x]]) Ans[lca] = max(Ans[lca], Mp[S[x]] + depth[x] - 2 * depth[lca]);
}
void work(int x, int f, int lca, int type) {
  if (type)
    add(x);
  else
    calc(x, lca);
  for (int i = Head[x]; ~i; i = Edge[i].nxt) {
    int to = Edge[i].to;
    if (to == f) continue;
    work(to, x, lca, type);
  }
}
void del(int x, int f) {
  Mp[S[x]] = -1;
  for (int i = Head[x]; ~i; i = Edge[i].nxt) {
    int to = Edge[i].to;
    if (to == f) continue;
    del(to, x);
  }
}
void solve(int x, int f, bool keep) {
  for (int i = Head[x]; ~i; i = Edge[i].nxt) {
    int to = Edge[i].to;
    if (to == f || to == son[x]) continue;
    solve(to, x, 0);
    Ans[x] = max(Ans[x], Ans[to]);
  }
  if (son[x]) solve(son[x], x, 1), Ans[x] = max(Ans[x], Ans[son[x]]);
  for (int i = Head[x]; ~i; i = Edge[i].nxt) {
    int to = Edge[i].to;
    if (to == f || to == son[x]) continue;
    work(to, x, x, 0);
    work(to, x, x, 1);
  }
  calc(x, x);
  add(x);
  if (!keep) del(x, x);
}
int main() {
  int n;
  Rd(n);
  memset(Mp, -1, sizeof(Mp));
  memset(Head, -1, sizeof(Head));
  for (int i = 2; i <= n; i++) {
    int f;
    char c[3];
    Rd(f);
    scanf("%s", c);
    Addedge(f, i, c[0]);
  }
  depth[1] = 1;
  dfs(1, 0);
  solve(1, 0, 1);
  for (int i = 1; i < n; i++) Pf(Ans[i]), putchar(' ');
  Pf(Ans[n]), putchar('\n');
  return 0;
}
