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>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  int a = 0, b = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') b = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    a = (a << 3) + (a << 1) + c - '0';
    c = getchar();
  }
  return a * b;
}
const int INF = 0x3f3f3f3f;
const int N = 5e5 + 7;
int tot, L[N], R[N], Id[N];
int head[N], cnt;
struct Edge {
  int to, nxt, w;
} e[N];
int deep[N], sz[N], hSon[N];
int ans[N], visited[N];
int f[N * 10], dis[N];
void addEdge(int u, int v, int w) {
  e[++cnt] = (Edge){v, head[u], w};
  head[u] = cnt;
}
void dfs1(int u, int f) {
  deep[u] = deep[f] + 1;
  sz[u] = 1;
  L[u] = ++tot;
  Id[tot] = u;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    dis[v] = dis[u] ^ e[i].w;
    dfs1(v, u);
    sz[u] += sz[v];
    if (sz[hSon[u]] < sz[v]) hSon[u] = v;
  }
  R[u] = tot;
}
void calc(int u) {
  if (f[dis[u]]) ans[u] = max(ans[u], f[dis[u]] - deep[u]);
  for (register int i = (0); i <= (21); i++)
    if (f[dis[u] ^ (1 << i)])
      ans[u] = max(ans[u], f[dis[u] ^ (1 << i)] - deep[u]);
  f[dis[u]] = max(f[dis[u]], deep[u]);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == hSon[u] || visited[v]) continue;
    for (register int j = (L[v]); j <= (R[v]); j++) {
      int x = Id[j];
      if (f[dis[x]]) ans[u] = max(ans[u], f[dis[x]] + deep[x] - 2 * deep[u]);
      for (register int k = (0); k <= (21); k++)
        if (f[dis[x] ^ (1 << k)])
          ans[u] = max(ans[u], f[dis[x] ^ (1 << k)] + deep[x] - 2 * deep[u]);
    }
    for (register int j = (L[v]); j <= (R[v]); j++)
      f[dis[Id[j]]] = max(f[dis[Id[j]]], deep[Id[j]]);
  }
}
void dfs2(int u, int keep) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == hSon[u]) continue;
    dfs2(v, 0);
    ans[u] = max(ans[u], ans[v]);
  }
  if (hSon[u])
    dfs2(hSon[u], 1), ans[u] = max(ans[u], ans[hSon[u]]), visited[hSon[u]] = 1;
  calc(u);
  if (hSon[u]) visited[hSon[u]] = 0;
  if (keep == 0)
    for (register int i = (L[u]); i <= (R[u]); i++) f[dis[Id[i]]] = 0;
}
int main() {
  int n = read();
  for (register int i = (2); i <= (n); i++) {
    int x;
    char s[10];
    scanf("%d%s", &x, s);
    addEdge(x, i, 1ll << (s[0] - 'a'));
  }
  dfs1(1, 1);
  dfs2(1, 1);
  for (register int i = (1); i <= (n); i++) printf("%d ", ans[i]);
  return 0;
}
