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 n, ans[500010], f[1 << 22], dep[500010], son[500010], dist[500010],
    size[500010];
vector<int> linker[500010], di[500010];
inline int read() {
  register int x = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
inline void update(int& x, int y) {
  if (x < y) x = y;
}
void dfs1(int x) {
  size[x] = 1;
  for (int i = 0; i < linker[x].size(); i++) {
    dep[linker[x][i]] = dep[x] + 1,
    dist[linker[x][i]] = dist[x] ^ (1 << di[x][i]);
    dfs1(linker[x][i]), size[x] += size[linker[x][i]];
    if (size[linker[x][i]] > size[son[x]]) son[x] = linker[x][i];
  }
}
void dfs3(int x, int pos) {
  for (register int i = 0; i < 22; i++)
    update(ans[pos], dep[x] + f[dist[x] ^ (1 << i)] - (dep[pos] << 1));
  update(ans[pos], dep[x] + f[dist[x]] - (dep[pos] << 1));
  for (int i = 0; i < linker[x].size(); i++) dfs3(linker[x][i], pos);
}
void dfs4(int x) {
  update(f[dist[x]], dep[x]);
  for (int i = 0; i < linker[x].size(); i++) dfs4(linker[x][i]);
}
void dfs5(int x) {
  f[dist[x]] = -1000000000;
  for (int i = 0; i < linker[x].size(); i++) dfs5(linker[x][i]);
}
void dfs2(int x, bool exi) {
  for (int i = 0; i < linker[x].size(); i++)
    if (linker[x][i] != son[x]) dfs2(linker[x][i], 0);
  if (son[x]) dfs2(son[x], 1), ans[x] = ans[son[x]];
  for (register int i = 0; i < 22; i++)
    update(ans[x], f[dist[x] ^ (1 << i)] - dep[x]);
  update(ans[x], f[dist[x]] - dep[x]);
  update(f[dist[x]], dep[x]);
  for (register int i = 0; i < linker[x].size(); i++)
    if (linker[x][i] != son[x]) {
      update(ans[x], ans[linker[x][i]]);
      dfs3(linker[x][i], x);
      dfs4(linker[x][i]);
    }
  if (!exi) dfs5(x);
}
inline void addedge(int x, int y, int z) {
  linker[x].push_back(y);
  di[x].push_back(z);
}
int main() {
  n = read();
  for (register int i = 2; i <= n; i++) {
    int fa = read(), ch;
    while (isspace(ch = getchar()))
      ;
    addedge(fa, i, ch - 'a');
  }
  for (register int i = 0; i < 1 << 22; i++) f[i] = -1000000000;
  dfs1(1);
  dfs2(1, 0);
  for (register int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
