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;
int mp[2000003 * 6], tot, nxt[2000003], point[2000003], v[2000003], c[2000003],
    val[2000003], siz[2000003], son[2000003];
int deep[2000003], ans[2000003], mx, n;
void add(int x, int y, int z) {
  tot++;
  nxt[tot] = point[x];
  point[x] = tot;
  v[tot] = y;
  c[tot] = z;
  tot++;
  nxt[tot] = point[y];
  point[y] = tot;
  v[tot] = x;
  c[tot] = z;
}
void dfs1(int x, int fa) {
  siz[x] = 1;
  deep[x] = deep[fa] + 1;
  for (int i = point[x]; i; i = nxt[i]) {
    if (v[i] == fa) continue;
    val[v[i]] = val[x] ^ c[i];
    dfs1(v[i], x);
    siz[x] += siz[v[i]];
    if (siz[son[x]] < siz[v[i]]) son[x] = v[i];
  }
}
int flag;
void get_ans(int dep, int x, int fa) {
  mx = max(mx, mp[val[x]] + deep[x] - 2 * dep);
  for (int i = 0; i <= 21; i++)
    mx = max(mx, mp[val[x] ^ (1 << i)] + deep[x] - 2 * dep);
  for (int i = point[x]; i; i = nxt[i])
    if (v[i] != fa && flag != v[i]) get_ans(dep, v[i], x);
}
void change(int x, int fa) {
  mp[val[x]] = max(mp[val[x]], deep[x]);
  for (int i = point[x]; i; i = nxt[i])
    if (v[i] != fa && flag != v[i]) change(v[i], x);
}
void init(int x, int fa) {
  mp[val[x]] = -1000000000;
  for (int i = point[x]; i; i = nxt[i])
    if (v[i] != fa && flag != v[i]) init(v[i], x);
}
void dfs(int x, int fa, bool k) {
  for (int i = point[x]; i; i = nxt[i])
    if (v[i] != fa && v[i] != son[x])
      dfs(v[i], x, 0), ans[x] = max(ans[x], ans[v[i]]);
  if (son[x])
    dfs(son[x], x, 1), ans[x] = max(ans[x], ans[son[x]]), flag = son[x];
  for (int i = point[x]; i; i = nxt[i])
    if (v[i] != son[x] && v[i] != fa)
      get_ans(deep[x], v[i], x), change(v[i], x);
  mx = max(mx, mp[val[x]] - deep[x]);
  for (int i = 0; i <= 21; i++) mx = max(mx, mp[val[x] ^ (1 << i)] - deep[x]);
  mp[val[x]] = max(mp[val[x]], deep[x]);
  ans[x] = max(ans[x], mx);
  flag = 0;
  if (!k) init(x, fa), mx = -1000000000;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    char c[3];
    scanf("%d%s", &x, c);
    add(x, i, 1 << (c[0] - 'a'));
  }
  for (int i = 0; i <= (1 << 22); i++) mp[i] = -1000000000;
  dfs1(1, 0);
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
