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;
const int MAXN = 5e5 + 10;
int h[MAXN], nx[MAXN << 1], to[MAXN << 1], type[MAXN << 1], tot,
    condition[MAXN];
int n, sz[MAXN], son[MAXN], bin[1 << ('v' - 'a' + 1)], dep[MAXN];
int ans[MAXN], cur_ans;
void add_edge(int x, int y, int z) {
  to[++tot] = y;
  nx[tot] = h[x];
  h[x] = tot;
  type[tot] = z;
}
void link(int x, int y, int z) {
  add_edge(x, y, z);
  add_edge(y, x, z);
}
void update(int num, int depth) {
  if (bin[num] != 0) {
    cur_ans = max(cur_ans, depth + bin[num]);
  }
  for (int i = 0; i <= ('v' - 'a'); i++) {
    int tmp = num ^ (1 << i);
    if (bin[tmp] != 0) {
      cur_ans = max(cur_ans, depth + bin[tmp]);
    }
  }
}
void cut(int num) { bin[num] = 0; }
void clear(int x, int y) {
  cut(condition[x]);
  for (int i = h[x]; i; i = nx[i]) {
    if (to[i] == y) continue;
    clear(to[i], x);
  }
}
void add(int num, int depth) { bin[num] = max(bin[num], depth); }
void dfs0(int x, int y, int cur) {
  sz[x] = 1;
  dep[x] = dep[y] + 1;
  condition[x] = cur;
  for (int i = h[x]; i; i = nx[i]) {
    if (to[i] == y) continue;
    dfs0(to[i], x, cur ^ (1 << type[i]));
    sz[x] += sz[to[i]];
    if (sz[son[x]] < sz[to[i]]) son[x] = to[i];
  }
}
void dfs1(int x, int y) {
  update(condition[x], dep[x]);
  for (int i = h[x]; i; i = nx[i]) {
    if (to[i] == y) continue;
    dfs1(to[i], x);
  }
}
void paint(int x, int y) {
  add(condition[x], dep[x]);
  for (int i = h[x]; i; i = nx[i]) {
    if (to[i] == y) continue;
    paint(to[i], x);
  }
}
void dfs2(int x, int y) {
  for (int i = h[x]; i; i = nx[i]) {
    if (to[i] == y || to[i] == son[x]) continue;
    dfs2(to[i], x);
  }
  if (son[x]) {
    dfs2(son[x], x);
  }
  cur_ans = 0;
  update(condition[x], dep[x]);
  add(condition[x], dep[x]);
  for (int i = h[x]; i; i = nx[i]) {
    if (to[i] == y || to[i] == son[x]) continue;
    dfs1(to[i], x);
    paint(to[i], x);
  }
  if (cur_ans != 0) {
    ans[x] = max(ans[x], cur_ans - (dep[x] << 1));
  }
  for (int i = h[x]; i; i = nx[i]) {
    if (to[i] == y) continue;
    ans[x] = max(ans[x], ans[to[i]]);
  }
  if (son[y] != x) {
    cur_ans = 0;
    clear(x, y);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    string tmp;
    int tmp0;
    cin >> tmp0 >> tmp;
    link(i, tmp0, tmp[0] - 'a');
  }
  dfs0(1, 0, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
