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;
int cnt[5000000];
int head[500010];
int to[1000010];
int nex[1000010];
int size[500010];
int son[500010];
int val[500010];
int dep[500010];
int tot;
int n;
int x, y;
char ch[2];
int ans[500010];
int tag[500010];
void add(int x, int y) {
  nex[++tot] = head[x];
  head[x] = tot;
  to[tot] = y;
}
void dfs(int x) {
  size[x] = 1;
  for (int i = head[x]; i; i = nex[i]) {
    dep[to[i]] = dep[x] + 1;
    val[to[i]] ^= val[x];
    dfs(to[i]);
    size[x] += size[to[i]];
    if (size[to[i]] > size[son[x]]) {
      son[x] = to[i];
    }
  }
}
void calc(int x, int anc) {
  ans[anc] = max(ans[anc], cnt[val[x]] + dep[x] - 2 * dep[anc]);
  for (int i = 0; i < 22; i++) {
    ans[anc] = max(ans[anc], cnt[val[x] ^ (1 << i)] + dep[x] - 2 * dep[anc]);
  }
  for (int i = head[x]; i; i = nex[i]) {
    calc(to[i], anc);
  }
}
void solve(int x, int opt) {
  if (opt == 1) {
    cnt[val[x]] = max(dep[x], cnt[val[x]]);
  } else {
    cnt[val[x]] = -1 << 30;
  }
  for (int i = head[x]; i; i = nex[i]) {
    solve(to[i], opt);
  }
}
void dsu_on_tree(int x, int opt) {
  for (int i = head[x]; i; i = nex[i]) {
    if (to[i] != son[x]) {
      dsu_on_tree(to[i], 0);
      ans[x] = max(ans[x], ans[to[i]]);
    }
  }
  if (son[x]) {
    dsu_on_tree(son[x], 1);
    ans[x] = max(ans[x], ans[son[x]]);
  }
  cnt[val[x]] = max(cnt[val[x]], dep[x]);
  ans[x] = max(ans[x], cnt[val[x]] - dep[x]);
  for (int i = 0; i < 22; i++) {
    ans[x] = max(ans[x], cnt[val[x] ^ (1 << i)] - dep[x]);
  }
  for (int i = head[x]; i; i = nex[i]) {
    if (to[i] != son[x]) {
      calc(to[i], x);
      solve(to[i], 1);
    }
  }
  if (!opt) {
    solve(x, -1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d%s", &x, ch);
    add(x, i);
    val[i] = 1 << (ch[0] - 'a');
  }
  dfs(1);
  for (int i = 0; i <= (1 << 22); i++) {
    cnt[i] = -1 << 30;
  }
  dsu_on_tree(1, 1);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
}
