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>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
const int N = 5e5 + 10;
int head[N], to[N], nex[N], value[N], cnt = 1;
int sz[N], son[N], dep[N], l[N], r[N], rk[N], dis[N], n, tot;
void add(int x, int y, int w) {
  to[cnt] = y;
  nex[cnt] = head[x];
  value[cnt] = w;
  head[x] = cnt++;
}
void dfs(int rt, int fa) {
  sz[rt] = 1, dep[rt] = dep[fa] + 1;
  l[rt] = ++tot, rk[tot] = rt;
  for (int i = head[rt]; i; i = nex[i]) {
    if (to[i] == fa) continue;
    dis[to[i]] = dis[rt] ^ value[i];
    dfs(to[i], rt);
    sz[rt] += sz[to[i]];
    if (!son[rt] || sz[to[i]] > sz[son[rt]]) son[rt] = to[i];
  }
  r[rt] = tot;
}
int ans[N], flag[N * 10];
void dfs(int rt, int fa, bool keep) {
  for (int i = head[rt]; i; i = nex[i]) {
    if (to[i] == fa || to[i] == son[rt]) continue;
    dfs(to[i], rt, 0);
    ans[rt] = max(ans[rt], ans[to[i]]);
  }
  if (son[rt]) {
    dfs(son[rt], rt, 1);
    ans[rt] = max(ans[rt], ans[son[rt]]);
  }
  if (flag[dis[rt]]) {
    ans[rt] = max(ans[rt], flag[dis[rt]] - dep[rt]);
  }
  for (int i = 0; i < 22; i++) {
    if (flag[(dis[rt] ^ (1 << i))])
      ans[rt] = max(ans[rt], flag[(dis[rt] ^ (1 << i))] - dep[rt]);
  }
  flag[dis[rt]] = max(flag[dis[rt]], dep[rt]);
  for (int i = head[rt]; i; i = nex[i]) {
    if (to[i] == fa || to[i] == son[rt]) continue;
    for (int j = l[to[i]]; j <= r[to[i]]; j++) {
      int now = rk[j];
      if (flag[dis[now]])
        ans[rt] = max(ans[rt], flag[dis[now]] + dep[now] - 2 * dep[rt]);
      for (int k = 0; k < 22; k++) {
        if (flag[dis[now] ^ (1 << k)])
          ans[rt] =
              max(ans[rt], flag[dis[now] ^ (1 << k)] + dep[now] - 2 * dep[rt]);
      }
    }
    for (int j = l[to[i]]; j <= r[to[i]]; j++) {
      int now = rk[j];
      flag[dis[now]] = max(flag[dis[now]], dep[now]);
    }
  }
  if (!keep) {
    for (int i = l[rt]; i <= r[rt]; i++) {
      int now = rk[i];
      flag[dis[now]] = 0;
    }
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    char c;
    cin >> x >> c;
    add(x, i, 1 << c - 'a');
  }
  dfs(1, 0);
  dfs(1, 0, 1);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " \n"[i == n];
  }
  return 0;
}
