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 dt[500050], ft[500050], dtime;
int hson[500050], sz[500050], dep[500050], id[500050], ans[500050], val[500050],
    w[500050];
int dist[(1 << 22)];
vector<int> v[500050];
template <class T>
void chkmax(T &a, T b) {
  if (a < b) a = b;
}
void dfs(int x) {
  dt[x] = ++dtime;
  id[dtime] = x;
  sz[x] = 1;
  for (auto y : v[x]) {
    dep[y] = dep[x] + 1;
    val[y] = val[x] ^ (1 << w[y]);
    dfs(y);
    sz[x] += sz[y];
    if (sz[hson[x]] < sz[y]) hson[x] = y;
  }
  ft[x] = dtime;
}
inline int mxlen(int value) {
  int ret = -1e9;
  if (dist[value]) ret = dist[value];
  for (int t = 0; t < 22; t++)
    if (dist[value ^ (1 << t)]) chkmax(ret, dist[value ^ (1 << t)]);
  return ret;
}
void DFS(int x, bool fg) {
  assert(x);
  for (auto y : v[x])
    if (y != hson[x]) DFS(y, 1);
  if (hson[x]) DFS(hson[x], 0);
  for (auto y : v[x]) {
    chkmax(ans[x], ans[y]);
    if (y != hson[x]) {
      for (int i = dt[y]; i <= ft[y]; i++) {
        chkmax(ans[x], mxlen(val[id[i]]) + dep[id[i]] - 2 * dep[x]);
      }
      for (int i = dt[y]; i <= ft[y]; i++) chkmax(dist[val[id[i]]], dep[id[i]]);
    }
  }
  chkmax(dist[val[x]], dep[x]);
  chkmax(ans[x], mxlen(val[x]) - dep[x]);
  if (fg)
    for (int i = dt[x]; i <= ft[x]; i++) dist[val[id[i]]] = 0;
}
void update(int x) {
  for (auto y : v[x]) {
    update(y);
    chkmax(ans[x], ans[y]);
  }
}
int x, n;
char s[10];
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d %s", &x, s);
    v[x].emplace_back(i);
    w[i] = (s[0] - 'a');
  }
  dfs(1);
  DFS(1, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
