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 long long read() {
  bool f = false;
  long long res = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch) f |= (ch == '-'), ch = getchar();
  while ('0' <= ch && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
  return f ? -res : res;
}
const int N = 5e5 + 10;
const int mod = 1e9 + 7;
int head[N], ver[N << 1], Next[N << 1], edge[N << 1], tot;
void add(int x, int y, int z) {
  ver[++tot] = y;
  edge[tot] = z;
  Next[tot] = head[x];
  head[x] = tot;
}
int f[1 << 22], flag;
int sz[N], son[N], d[N], D[N], ans[N], maxn, lca;
void dfsson(int u, int fa) {
  sz[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fa) continue;
    d[v] = d[u] + 1;
    D[v] = D[u] ^ (1 << edge[i]);
    dfsson(v, u);
    sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
void cal(int u, int fa) {
  if (f[D[u]]) maxn = max(maxn, d[u] + f[D[u]] - lca);
  for (int i = 0; i < 22; i++) {
    if (f[D[u] ^ (1 << i)]) maxn = max(maxn, f[D[u] ^ (1 << i)] + d[u] - lca);
  }
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fa) continue;
    cal(v, u);
  }
}
void update(int u, int fa) {
  f[D[u]] = max(f[D[u]], d[u]);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fa) continue;
    update(v, u);
  }
}
void clear(int u, int fa) {
  f[D[u]] = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fa) continue;
    clear(v, u);
  }
}
void dfs(int u, int fa, int keep) {
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fa || v == son[u]) continue;
    dfs(v, u, 0);
  }
  if (son[u]) {
    dfs(son[u], u, 1);
    flag = u;
  }
  lca = 2 * d[u];
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fa) continue;
    maxn = max(maxn, ans[v]);
  }
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fa || v == son[u]) continue;
    cal(v, u);
    update(v, u);
  }
  if (f[D[u]]) maxn = max(maxn, d[u] + f[D[u]] - lca);
  for (int i = 0; i < 22; i++) {
    if (f[D[u] ^ (1 << i)]) maxn = max(maxn, f[D[u] ^ (1 << i)] + d[u] - lca);
  }
  f[D[u]] = max(f[D[u]], d[u]);
  ans[u] = maxn;
  flag = 0;
  if (!keep) {
    clear(u, fa);
    maxn = 0;
  }
}
int main() {
  int n = read();
  for (int i = 2; i <= n; i++) {
    int x = read(), c = getchar() - 'a';
    add(x, i, c);
    add(i, x, c);
  }
  dfsson(1, 0);
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
