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 node {
  int to, next;
} e[500005 << 1];
int head[500005], siz[500005], cnt, n, S[1 << 23], val[500005], son[500005],
    dep[500005], ans[500005], tmp_ans;
void add(int x, int y) {
  e[cnt] = (node){y, head[x]};
  head[x] = cnt++;
}
void dfs1(int x, int from) {
  dep[x] = dep[from] + 1, siz[x] = 1, val[x] ^= val[from];
  for (int i = head[x]; i != -1; i = e[i].next) {
    int to1 = e[i].to;
    if (to1 != from)
      dfs1(to1, x), siz[x] += siz[to1],
          son[x] = (siz[to1] > siz[son[x]] ? to1 : son[x]);
  }
}
void add(int x, int from, bool op) {
  if (op)
    S[val[x]] = max(dep[x], S[val[x]]);
  else
    S[val[x]] = -0x3f3f3f3f;
  for (int i = head[x]; i != -1; i = e[i].next) {
    int to1 = e[i].to;
    if (to1 != from) add(to1, x, op);
  }
}
void get(int x) {
  tmp_ans = max(tmp_ans, S[val[x]] + dep[x]);
  for (int i = 0; i <= 22; i++)
    tmp_ans = max(tmp_ans, S[val[x] ^ (1 << i)] + dep[x]);
}
void get_ans(int x, int from) {
  get(x);
  for (int i = head[x]; i != -1; i = e[i].next) {
    int to1 = e[i].to;
    if (to1 != from) get_ans(to1, x);
  }
}
void dfs2(int x, int from, int op) {
  for (int i = head[x]; i != -1; i = e[i].next) {
    int to1 = e[i].to;
    if (to1 != from && to1 != son[x]) dfs2(to1, x, 0);
  }
  if (son[x]) dfs2(son[x], x, 1), ans[x] = ans[son[x]];
  for (int i = head[x]; i != -1; i = e[i].next) {
    int to1 = e[i].to;
    if (to1 != from && to1 != son[x])
      get_ans(to1, x), ans[x] = max(ans[x], ans[to1]), add(to1, x, 1);
  }
  get(x);
  S[val[x]] = max(dep[x], S[val[x]]);
  ;
  ans[x] = max(ans[x], tmp_ans - (dep[x] << 1)), tmp_ans = 0;
  if (!op) add(x, from, 0);
}
char rr[2];
int main() {
  scanf("%d", &n);
  memset(head, -1, sizeof(head));
  memset(S, -0x3f, sizeof(S));
  for (int i = 2, x; i <= n; i++)
    scanf("%d%s", &x, rr), val[i] = 1 << (rr[0] - 'a'), add(x, i), add(i, x);
  dfs1(1, 0);
  dfs2(1, 0, 1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
