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 N = 5e5;
const int M = N + 7;
const int MOD = 1e9 + 7;
const long long INF = 1e16 + 17;
int st[M], ft[M], tim, ver[M];
int sz[M], big[M];
int h[M], xr[M];
vector<pair<int, int> > g[M];
int mask[M * 10];
int ans[M];
void preCalc(int v) {
  st[v] = ++tim;
  ver[tim] = v;
  sz[v] = 1;
  for (auto u : g[v]) {
    h[u.first] = h[v] + 1;
    xr[u.first] = xr[v] ^ (1 << u.second);
    preCalc(u.first);
    sz[v] += sz[u.first];
    if (sz[u.first] > sz[big[v]]) {
      big[v] = u.first;
    }
  }
  ft[v] = tim;
}
void dfs(int v, int keep = 0) {
  for (auto u : g[v]) {
    if (u.first != big[v]) {
      dfs(u.first);
      ans[v] = max(ans[v], ans[u.first]);
    }
  }
  if (big[v]) dfs(big[v], 1);
  ans[v] = max(ans[v], ans[big[v]]);
  for (int i = -1; i < 22; ++i) {
    int msk = (i >= 0 ? 1 << i : 0);
    msk ^= xr[v];
    ans[v] = max(ans[v], mask[msk] - h[v]);
  }
  mask[xr[v]] = max(mask[xr[v]], h[v]);
  for (auto u : g[v]) {
    if (u.first == big[v]) continue;
    for (int i = st[u.first]; i <= ft[u.first]; ++i) {
      int to = ver[i];
      for (int j = -1; j < 22; ++j) {
        int msk = j >= 0 ? 1 << j : 0;
        msk = msk ^ xr[to];
        if (mask[msk]) ans[v] = max(ans[v], mask[msk] - h[v] + h[to] - h[v]);
      }
    }
    for (int i = st[u.first]; i <= ft[u.first]; ++i) {
      int to = ver[i];
      mask[xr[to]] = max(mask[xr[to]], h[to]);
    }
  }
  if (!keep) {
    for (int i = st[v]; i <= ft[v]; ++i) {
      int u = ver[i];
      mask[xr[u]] = 0;
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int par;
    char x;
    scanf("%d %c", &par, &x);
    g[par].push_back(make_pair(i, x - 'a'));
  }
  h[1] = 1;
  preCalc(1);
  dfs(1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
