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;
inline char gc() {
  static char now[1 << 16], *S, *T;
  if (T == S) {
    T = (S = now) + fread(now, 1, 1 << 16, stdin);
    if (T == S) return EOF;
  }
  return *S++;
}
inline long long read() {
  register long long x = 0, f = 1;
  char ch = gc();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = gc();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = gc();
  }
  return (f == 1) ? x : -x;
}
struct edge {
  int to, nxt, dis;
} g[1200001];
int head[1200001], tot, n, m;
inline void made(int from, int to, int dis) {
  g[++tot].to = to;
  g[tot].nxt = head[from];
  head[from] = tot;
  g[tot].dis = dis;
}
int sz[1200001], dep[1200001], wson[1200001];
int s[1200001], a[1200001], F[10000001], ans[1200001];
void dfs0(int u, int fa) {
  sz[u] = 1;
  dep[u] = dep[fa] + 1;
  for (int i = head[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == fa) continue;
    s[v] = a[v] ^ s[u] ^ g[i].dis;
    dfs0(v, u);
    sz[u] += sz[v];
    if (sz[wson[u]] < sz[v]) wson[u] = v;
  }
}
void get(int u, int fa, int wht) {
  if (wht)
    F[s[u]] = max(F[s[u]], dep[u]);
  else
    F[s[u]] = 0;
  for (int i = head[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == fa) continue;
    get(v, u, wht);
  }
}
void calc(int zx, int u, int fa) {
  if (F[s[u]]) ans[zx] = max(F[s[u]] + dep[u] - 2 * dep[zx], ans[zx]);
  for (int i = 0, two = 1; i < 22; i++, two <<= 1) {
    if (F[s[u] ^ two])
      ans[zx] = max(F[s[u] ^ two] + dep[u] - 2 * dep[zx], ans[zx]);
  }
  for (int i = head[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == fa) continue;
    calc(zx, v, u);
  }
}
void doit(int u, int fa, int wht) {
  for (int i = head[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == fa || v == wson[u]) continue;
    doit(v, u, 0);
  }
  if (wson[u]) doit(wson[u], u, 1);
  if (F[s[u]]) ans[u] = max(F[s[u]] - dep[u], ans[u]);
  for (int i = 0, two = 1; i < 22; i++, two <<= 1) {
    if (F[s[u] ^ two]) ans[u] = max(F[s[u] ^ two] - dep[u], ans[u]);
  }
  F[s[u]] = max(F[s[u]], dep[u]);
  for (int i = head[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == fa || v == wson[u]) continue;
    calc(u, v, u);
    get(v, u, 1);
  }
  if (!wht) get(u, fa, 0);
}
void dfs1(int u, int fa) {
  for (int i = head[u]; i; i = g[i].nxt) {
    int v = g[i].to;
    if (v == fa) continue;
    dfs1(v, u);
    ans[u] = max(ans[u], ans[v]);
  }
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int u = read();
    char ch = gc();
    while (!isalpha(ch)) ch = gc();
    made(i + 1, u, (1 << (ch - 'a')));
    made(u, i + 1, (1 << (ch - 'a')));
  }
  dfs0(1, 0);
  doit(1, 0, 0);
  dfs1(1, 0);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
