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;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
int n, m, i, j, x, f[1 << 22], son[500005], sz[500005], dep[500005],
    dis[500005], first[500005], ed[500005], ti, mp[500005], ans[500005];
char c;
vector<pair<int, int> > e[500005];
void dfs1(int x) {
  first[x] = ++ti;
  mp[ti] = x;
  sz[x] = 1;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    dep[it->first] = dep[x] + 1;
    dis[it->first] = (dis[x] ^ it->second);
    dfs1(it->first);
    sz[x] += sz[it->first];
    if (!son[x] || sz[it->first] > sz[son[x]]) son[x] = it->first;
  }
  ed[x] = ti;
}
void dfs2(int x, bool is_lys) {
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)
    if (son[x] != it->first) {
      dfs2(it->first, 0);
      ans[x] = max(ans[x], ans[it->first]);
    }
  if (son[x]) {
    dfs2(son[x], 1);
    ans[x] = max(ans[x], ans[son[x]]);
  }
  int i, j;
  ans[x] = max(ans[x], f[dis[x]] - dep[x]);
  for ((i) = (0); (i) <= (21); (i)++)
    ans[x] = max(ans[x], f[dis[x] ^ (1 << i)] - dep[x]);
  f[dis[x]] = max(f[dis[x]], dep[x]);
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)
    if (son[x] != it->first) {
      for ((j) = (first[it->first]); (j) <= (ed[it->first]); (j)++) {
        ans[x] = max(ans[x], dep[mp[j]] + f[dis[mp[j]]] - 2 * dep[x]);
        for ((i) = (0); (i) <= (21); (i)++)
          ans[x] =
              max(ans[x], dep[mp[j]] + f[dis[mp[j]] ^ (1 << i)] - 2 * dep[x]);
      }
      for ((j) = (first[it->first]); (j) <= (ed[it->first]); (j)++) {
        f[dis[mp[j]]] = max(f[dis[mp[j]]], dep[mp[j]]);
      }
    }
  if (!is_lys)
    for ((i) = (first[x]); (i) <= (ed[x]); (i)++) f[dis[mp[i]]] = -0x3bbbbbbb;
}
int main() {
  read(n);
  for ((i) = (2); (i) <= (n); (i)++) {
    read(x);
    scanf(" %c", &c);
    e[x].push_back(make_pair(i, (1 << (c - 'a'))));
  }
  memset((f), (-(0x16)), (sizeof((f))));
  dfs1(1);
  dfs2(1, 1);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) printf("%d ", ans[i]);
  return 0;
}
