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;
template <typename T>
void read(T& x) {
  static char c;
  static int f;
  for (c = getchar(), f = 1; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -f;
  for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + (c & 15);
  x *= f;
}
template <typename T>
void write(T x) {
  static char q[65];
  int cnt = 0;
  if (x < 0) putchar('-'), x = -x;
  q[++cnt] = x % 10, x /= 10;
  while (x) q[++cnt] = x % 10, x /= 10;
  while (cnt) putchar(q[cnt--] + '0');
}
const int maxn = 500005;
int bro[maxn], son[maxn], vis[maxn], dfn[maxn], cnt, pos[maxn], dp[maxn],
    sz[maxn], ss[maxn];
void dfs(int u) {
  pos[dfn[u] = ++cnt] = u;
  sz[u] = 1;
  int mx = 0;
  for (int v = son[u]; v; v = bro[v]) {
    vis[v] ^= vis[u];
    dp[v] = dp[u] + 1;
    dfs(v);
    sz[u] += sz[v];
    if (sz[v] > mx) {
      mx = sz[v];
      ss[u] = v;
    }
  }
}
int all[25], num, bk[1 << 22], MX[maxn];
void solve(int u, int er) {
  for (int v = son[u]; v; v = bro[v]) {
    if (v == ss[u]) continue;
    solve(v, false);
  }
  if (ss[u]) solve(ss[u], true);
  for (int v = son[u]; v; v = bro[v]) {
    MX[u] = max(MX[u], MX[v]);
    if (v == ss[u]) continue;
    int bg = dfn[v], ed = bg + sz[v];
    for (int i = bg; i != ed; ++i) {
      int x = pos[i];
      for (int j = 0; j != num; ++j)
        MX[u] = max(MX[u], bk[vis[x] ^ all[j]] + dp[x] - dp[u] * 2);
    }
    for (int i = bg; i != ed; ++i) {
      int x = pos[i];
      bk[vis[x]] = max(bk[vis[x]], dp[x]);
    }
  }
  for (int j = 0; j != num; ++j)
    MX[u] = max(MX[u], bk[vis[u] ^ all[j]] - dp[u]);
  bk[vis[u]] = max(bk[vis[u]], dp[u]);
  if (!er) {
    int bg = dfn[u], ed = bg + sz[u];
    for (int i = bg; i != ed; ++i) {
      bk[vis[pos[i]]] = -0x3f3f3f3f;
    }
  }
}
int main() {
  int n;
  read(n);
  for (int i = 2; i <= n; ++i) {
    int f;
    read(f);
    char c = getchar();
    while (c < 'a' || c > 'v') c = getchar();
    bro[i] = son[f], son[f] = i;
    vis[i] = 1 << (c - 'a');
  }
  for (int i = 0; i < 22; ++i) all[num++] = 1 << i;
  all[num++] = 0;
  dfs(1);
  memset(bk, -0x3f, sizeof bk);
  solve(1, 0);
  for (int i = 1; i <= n; ++i) write(MX[i]), putchar(" \n"[i == n]);
  return 0;
}
