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 n, tot, dep, now;
char s[11];
int head[510000], nex[510000], to[510000];
int val[510000], v[(1 << 23) + 10];
int size[510000], son[510000], deep[510000], ans[510000];
void add(int x, int y) {
  tot++;
  nex[tot] = head[x];
  head[x] = tot;
  to[tot] = y;
}
void dfs(int x, int y) {
  size[x] = 1;
  deep[x] = deep[y] + 1;
  val[x] ^= val[y];
  for (int i = head[x]; i; i = nex[i]) {
    dfs(to[i], x);
    size[x] += size[to[i]];
    son[x] = size[to[i]] > size[son[x]] ? to[i] : son[x];
  }
}
void opt1(int x) {
  if (v[val[x]]) now = max(now, v[val[x]] + deep[x] - dep * 2);
  for (int i = 'a', t; i <= 'v'; i++)
    if (t = v[val[x] ^ (1 << i - 'a')]) now = max(now, t + deep[x] - dep * 2);
}
void opt2(int x) { v[val[x]] = max(v[val[x]], deep[x]); }
void upd(int x) {
  opt1(x);
  for (int i = head[x]; i; i = nex[i]) upd(to[i]);
}
void ins(int x) {
  opt2(x);
  for (int i = head[x]; i; i = nex[i]) ins(to[i]);
}
void del(int x) {
  v[val[x]] = 0;
  for (int i = head[x]; i; i = nex[i]) del(to[i]);
}
void dfs1(int x, int tp) {
  for (int i = head[x]; i; i = nex[i])
    if (to[i] != son[x]) dfs1(to[i], 0);
  if (son[x]) dfs1(son[x], 1);
  dep = deep[x];
  opt1(x);
  opt2(x);
  for (int i = head[x]; i; i = nex[i])
    if (to[i] != son[x]) upd(to[i]), ins(to[i]);
  ans[x] = now;
  if (!tp) {
    now = 0;
    del(x);
  }
}
void dfs2(int x) {
  for (int i = head[x]; i; i = nex[i]) {
    dfs2(to[i]);
    ans[x] = max(ans[x], ans[to[i]]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2, x; i <= n; i++) {
    scanf("%d%s", &x, s + 1);
    val[i] = 1 << (s[1] - 'a');
    add(x, i);
  }
  dfs(1, 0);
  dfs1(1, 0);
  dfs2(1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
