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>
template <class T>
inline T max(const T &x, const T &y) {
  return x > y ? x : y;
}
template <class T>
inline T min(const T &x, const T &y) {
  return x < y ? x : y;
}
template <class T>
inline bool chkmax(T &x, const T &y) {
  return x < y ? x = y, true : false;
}
template <class T>
inline bool chkmin(T &x, const T &y) {
  return x > y ? x = y, true : false;
}
inline int read() {
  register int x = 0, v = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') v = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * v;
}
const int MAXN = 5e5;
struct Edge {
  int to, w, nxt;
  Edge(int _to = 0, int _w = 0, int _nxt = 0) : to(_to), w(_w), nxt(_nxt) {}
} e[MAXN];
int n, edge;
int size[MAXN | 1], son[MAXN | 1], fse[MAXN | 1], ans[MAXN | 1], sonw[MAXN | 1],
    dep[MAXN | 1];
int buck[1 << 22], state[MAXN | 1];
inline void add_edge(int x, int y, int z) {
  e[++edge] = Edge(y, z, fse[x]);
  fse[x] = edge;
}
void pre_dfs(int x) {
  size[x] = 1;
  for (int k = fse[x]; k; k = e[k].nxt) {
    int to = e[k].to, w = e[k].w;
    dep[to] = dep[x] + 1;
    state[to] = state[x] ^ (1 << w);
    pre_dfs(to);
    size[x] += size[to];
    if (size[to] > size[son[x]]) son[x] = to;
  }
}
void dfs2(int x, int val, int frm) {
  if (val == 1)
    buck[state[x]] = -2e9;
  else if (val == 2) {
    chkmax(ans[frm], buck[state[x]] + dep[x] - 2 * dep[frm]);
    for (int i = 0; i < 22; ++i)
      chkmax(ans[frm], buck[state[x] ^ (1 << i)] + dep[x] - 2 * dep[frm]);
  } else
    chkmax(buck[state[x]], dep[x]);
  for (int k = fse[x]; k; k = e[k].nxt) {
    int to = e[k].to;
    dfs2(to, val, frm);
  }
}
void dfs1(int x) {
  for (int k = fse[x]; k; k = e[k].nxt) {
    int to = e[k].to;
    if (to == son[x]) continue;
    dfs1(to);
    chkmax(ans[x], ans[to]);
    dfs2(to, 1, x);
  }
  if (son[x]) dfs1(son[x]);
  chkmax(ans[x], ans[son[x]]);
  for (int k = fse[x]; k; k = e[k].nxt) {
    int to = e[k].to;
    if (to == son[x]) continue;
    dfs2(to, 2, x);
    dfs2(to, 3, x);
  }
  chkmax(buck[state[x]], dep[x]);
  chkmax(ans[x], buck[state[x]] - dep[x]);
  for (int i = 0; i < 22; ++i)
    chkmax(ans[x], buck[state[x] ^ (1 << i)] - dep[x]);
}
int main() {
  n = read();
  for (int i = 2; i <= n; ++i) {
    int fa = read(), w = getchar() - 'a';
    add_edge(fa, i, w);
  }
  memset(buck, 0xcf, sizeof(buck));
  pre_dfs(1);
  dfs1(1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
