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>
const int maxn = 500005, maxm = maxn, maxk = 23;
int n, e, cnt;
int start[maxn], to[maxm], then[maxm], worth[maxm], ans[maxn], size[maxn],
    iptson[maxn], dis[maxn], in[maxn], out[maxn], pos[maxn], maxx[1 << maxk],
    dep[maxn];
inline int max(int a, int b) { return a > b ? a : b; }
inline void add(int x, int y, int z) {
  then[++e] = start[x], start[x] = e, to[e] = y, worth[e] = z;
}
void dfs1(int x) {
  iptson[x] = -1, size[x] = 1, in[x] = ++cnt, pos[cnt] = x;
  for (int i = start[x]; i; i = then[i]) {
    int y = to[i];
    dis[y] = dis[x] ^ (1 << (worth[i])), dep[y] = dep[x] + 1;
    dfs1(y), size[x] += size[y];
    if (iptson[x] == -1 || size[y] > size[iptson[x]]) iptson[x] = y;
  }
  out[x] = cnt;
}
void dfs2(int x) {
  for (int i = start[x]; i; i = then[i]) {
    int y = to[i];
    if (y == iptson[x]) continue;
    dfs2(y);
    ans[x] = max(ans[x], ans[y]);
    for (int j = in[y]; j <= out[y]; j++) maxx[dis[pos[j]]] = -1000000000;
  }
  if (iptson[x] != -1) dfs2(iptson[x]), ans[x] = max(ans[x], ans[iptson[x]]);
  ans[x] = max(ans[x], maxx[dis[x]] - dep[x]);
  for (int i = 0; i <= 21; i++)
    ans[x] = max(ans[x], maxx[dis[x] ^ (1 << i)] - dep[x]);
  maxx[dis[x]] = max(maxx[dis[x]], dep[x]);
  for (int i = start[x]; i; i = then[i]) {
    int y = to[i];
    if (y == iptson[x]) continue;
    for (int j = in[y]; j <= out[y]; j++) {
      ans[x] = max(ans[x], maxx[dis[pos[j]]] + dep[pos[j]] - 2 * dep[x]);
      for (int k = 0; k <= 21; k++)
        ans[x] = max(ans[x],
                     maxx[dis[pos[j]] ^ (1 << k)] + dep[pos[j]] - 2 * dep[x]);
    }
    for (int j = in[y]; j <= out[y]; j++)
      maxx[dis[pos[j]]] = max(maxx[dis[pos[j]]], dep[pos[j]]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    char c;
    scanf("%d", &x);
    for (c = getchar(); c < 'a' || c > 'v'; c = getchar())
      ;
    add(x, i, c - 97);
  }
  for (int i = 0; i < 1 << maxk; i++) maxx[i] = -1000000000;
  dfs1(1), dfs2(1);
  for (int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n' : ' ');
  return 0;
}
