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;
const int BS = 1e5 + 5;
char buf[BS], *S, *T;
inline char gc() {
  if (S == T) T = (S = buf) + fread(buf, 1, BS, stdin);
  return S != T ? *(S++) : EOF;
}
inline int in() {
  int x = 0, f = 1;
  char c = gc();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = gc();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = gc();
  return x * f;
}
const int N = 5e5 + 5, M = 1 << 22 | 5;
int n, tot;
char s[N];
int dep[N], sz[N], fa[N], son[N], dfn1[N], dfn2[N], p[N], ans[N];
int a[N], b[M];
vector<int> v[N];
void dfs1(int x, int val) {
  int mx = 0;
  dfn1[x] = ++tot;
  p[tot] = x;
  a[x] = val;
  sz[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    int y = v[x][i];
    dfs1(y, val ^ (1 << (s[y] - 'a')));
    sz[x] += sz[y];
    if (sz[y] > mx) son[x] = y, mx = sz[y];
  }
  dfn2[x] = tot;
}
void dfs2(int x) {
  for (int i = 0; i < v[x].size(); i++) {
    int y = v[x][i];
    if (y == son[x]) continue;
    dfs2(y);
    ans[x] = max(ans[x], ans[y]);
  }
  if (son[x]) dfs2(son[x]), ans[x] = max(ans[x], ans[son[x]]);
  for (int i = -1; i <= 21; i++) {
    int o = i < 0 ? a[x] : a[x] ^ (1 << i);
    if (b[o]) ans[x] = max(ans[x], dep[x] + b[o] - (dep[x] << 1));
  }
  b[a[x]] = max(b[a[x]], dep[x]);
  for (int i = 0; i < v[x].size(); i++) {
    int y = v[x][i];
    if (y == son[x]) continue;
    for (int j = dfn1[y]; j <= dfn2[y]; j++) {
      int z = p[j];
      for (int i = -1; i <= 21; i++) {
        int o = i < 0 ? a[z] : a[z] ^ (1 << i);
        if (b[o]) ans[x] = max(ans[x], dep[z] + b[o] - (dep[x] << 1));
      }
    }
    for (int j = dfn1[y]; j <= dfn2[y]; j++)
      b[a[p[j]]] = max(b[a[p[j]]], dep[p[j]]);
  }
  if (son[fa[x]] != x)
    for (int i = dfn1[x]; i <= dfn2[x]; i++) b[a[p[i]]] = 0;
}
int main() {
  n = in();
  dep[1] = 1;
  for (int i = 2; i <= n; i++) {
    fa[i] = in(), s[i] = gc();
    dep[i] = dep[fa[i]] + 1;
    v[fa[i]].push_back(i);
  }
  dfs1(1, 0);
  dfs2(1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
