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;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
int mymap[4300000];
int dep[500000 + 7], cost[500000 + 7], sub[500000 + 7], ans[500000 + 7],
    big[500000 + 7];
vector<int> graph[500000 + 7], alp[500000 + 7], vec;
void dfs0(int u, int p, int d, int c) {
  dep[u] = d;
  sub[u] = 1;
  cost[u] = c;
  int v, a;
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i];
    if (v == p) continue;
    a = alp[u][i];
    dfs0(v, u, d + 1, (c ^ (1 << a)));
    sub[u] += sub[v];
  }
}
void add(int u, int p, int r) {
  int a = cost[u];
  if (u != r) {
    int s = mymap[a];
    if (s > 0) ans[r] = max(ans[r], dep[u] + s - 2 * dep[r]);
    for (int i = 0; i < 22; i++) {
      s = a ^ (1 << i);
      s = mymap[s];
      if (s > 0) ans[r] = max(ans[r], dep[u] + s - 2 * dep[r]);
    }
    vec.push_back(u);
  }
  int v;
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i];
    if (v == p || big[v]) continue;
    if (u == r) vec.clear();
    add(v, u, r);
    if (u == r) {
      for (int j = 0; j < vec.size(); j++) {
        v = vec[j];
        mymap[cost[v]] = max(dep[v], mymap[cost[v]]);
      }
    }
  }
}
void rmv(int u, int p) {
  int v;
  mymap[cost[u]] = 0;
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i];
    if (v == p || big[v]) continue;
    rmv(v, u);
  }
}
void dsu(int u, int p, int kp) {
  int mx = 0, bg = -1;
  int v;
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i];
    if (v == p) continue;
    if (sub[v] > mx) {
      mx = sub[v];
      bg = v;
    }
  }
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i];
    if (v == p || v == bg) continue;
    dsu(v, u, 0);
  }
  if (bg != -1) {
    dsu(bg, u, 1);
    big[bg] = 1;
  }
  add(u, p, u);
  int a = cost[u];
  a = mymap[a];
  if (a > 0) ans[u] = max(ans[u], a - dep[u]);
  for (int i = 0; i < 22; i++) {
    a = cost[u] ^ (1 << i);
    a = mymap[a];
    if (a > 0) ans[u] = max(ans[u], a - dep[u]);
  }
  for (int i = 0; i < graph[u].size(); i++) {
    v = graph[u][i];
    if (v == p) continue;
    ans[u] = max(ans[u], ans[v]);
  }
  if (bg != -1) big[bg] = 0;
  if (kp == 0)
    rmv(u, p);
  else
    mymap[cost[u]] = max(mymap[cost[u]], dep[u]);
}
int main() {
  char ch[3];
  int n, a;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &a);
    scanf("%s", ch);
    graph[i].push_back(a);
    graph[a].push_back(i);
    alp[a].push_back(ch[0] - 'a');
    alp[i].push_back(ch[0] - 'a');
  }
  dfs0(1, -1, 0, 0);
  dsu(1, -1, 1);
  for (int i = 1; i <= n; i++) {
    if (i > 1) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
