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>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
int n;
int fa[500010], sta[500010], de[500010], siz[500010], son[500010], ans[500010],
    val[4500010];
char s[5];
struct edge {
  int to, nxt, v;
} e[500010];
int head[500010], edge_cnt;
void add(int from, int to, int val) {
  e[++edge_cnt] = (edge){to, head[from], val};
  head[from] = edge_cnt;
}
void dfs_pre(int x) {
  de[x] = de[fa[x]] + 1, siz[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    sta[y] = sta[x] ^ e[i].v, dfs_pre(y), siz[x] += siz[y];
    if (siz[y] > siz[son[x]]) son[x] = y;
  }
}
void calc(int x, int v) {
  if (v == 1)
    val[sta[x]] = max(val[sta[x]], de[x]);
  else
    val[sta[x]] = -1000000000;
  for (int i = head[x]; i; i = e[i].nxt) calc(e[i].to, v);
}
void work(int x, int rt) {
  ans[rt] = max(ans[rt], de[x] + val[sta[x]]);
  for (int i = 0; i <= 21; ++i)
    ans[rt] = max(ans[rt], de[x] + val[sta[x] ^ (1 << i)]);
  for (int i = head[x]; i; i = e[i].nxt) work(e[i].to, rt);
}
void dfs_ans(int x, int keep) {
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (y == son[x]) continue;
    dfs_ans(y, 0);
  }
  if (son[x]) dfs_ans(son[x], 1);
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (y == son[x]) continue;
    work(y, x), calc(y, 1);
  }
  val[sta[x]] = max(val[sta[x]], de[x]),
  ans[x] = max(ans[x], de[x] + val[sta[x]]);
  for (int i = 0; i <= 21; ++i)
    ans[x] = max(ans[x], de[x] + val[sta[x] ^ (1 << i)]);
  ans[x] -= de[x] * 2;
  for (int i = head[x]; i; i = e[i].nxt) ans[x] = max(ans[x], ans[e[i].to]);
  if (!keep) calc(x, -1);
}
int main() {
  read(n), memset(val, -0x3f, sizeof(val));
  for (int i = 2; i <= n; ++i) {
    read(fa[i]), scanf("%s", s);
    add(fa[i], i, 1 << (s[0] - 'a'));
  }
  dfs_pre(1), dfs_ans(1, 0);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
