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) {
  int f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
  x *= f;
}
const int N = 5e5 + 5;
const int M = 1e6 + 5;
const int K = 22;
vector<pair<int, int> > Edge[N];
inline void addedge(int x, int y, int z) { Edge[x].push_back(make_pair(y, z)); }
int n;
int Size[N], son[N], dep[N], dis[N], L[N], R[N], id[N], cnt;
inline void dfsA(int x) {
  Size[x] = 1;
  L[x] = ++cnt;
  id[cnt] = x;
  for (int i = 0; i < Edge[x].size(); i++) {
    int y = Edge[x][i].first, z = Edge[x][i].second;
    dis[y] = dis[x] ^ z;
    dep[y] = dep[x] + 1;
    dfsA(y);
    Size[x] += Size[y];
    if (Size[y] > Size[son[x]]) son[x] = y;
  }
  R[x] = cnt;
}
int ans[N], val[1 << K];
inline void dfsB(int x, bool keep) {
  for (int i = 0; i < Edge[x].size(); i++) {
    int y = Edge[x][i].first;
    if (y == son[x]) continue;
    dfsB(y, 0);
    ans[x] = max(ans[x], ans[y]);
  }
  if (son[x]) {
    dfsB(son[x], 1);
    ans[x] = max(ans[x], ans[son[x]]);
  }
  if (val[dis[x]]) ans[x] = max(ans[x], val[dis[x]] - dep[x]);
  for (int i = 0; i <= 21; i++)
    if (val[dis[x] ^ (1 << i)])
      ans[x] = max(ans[x], val[dis[x] ^ (1 << i)] - dep[x]);
  val[dis[x]] = max(val[dis[x]], dep[x]);
  for (int i = 0; i < Edge[x].size(); i++) {
    int y = Edge[x][i].first;
    if (y == son[x]) continue;
    for (int j = L[y]; j <= R[y]; j++) {
      int z = id[j];
      if (val[dis[z]]) ans[x] = max(ans[x], val[dis[z]] + dep[z] - 2 * dep[x]);
      for (int k = 0; k <= 21; k++)
        if (val[dis[z] ^ (1 << k)])
          ans[x] = max(ans[x], val[dis[z] ^ (1 << k)] + dep[z] - 2 * dep[x]);
    }
    for (int j = L[y]; j <= R[y]; j++)
      val[dis[id[j]]] = max(val[dis[id[j]]], dep[id[j]]);
  }
  if (!keep)
    for (int i = L[x]; i <= R[x]; i++) val[dis[id[i]]] = 0;
}
int main() {
  read(n);
  for (int x, y = 2; y <= n; y++) {
    char ch;
    read(x);
    do {
      scanf("%c", &ch);
    } while (isspace(ch));
    addedge(x, y, (1 << (ch - 'a')));
  }
  dfsA(1);
  dfsB(1, 1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  puts("");
  return 0;
}
