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 read();
const int N = 500005, inf = 0x3f3f3f3f;
int n;
int fa[N];
int a[N];
struct Edge {
  int v, w, nxt;
} e[N];
int fir[N], o;
void add(int u, int v, int w) {
  e[++o] = (Edge){v, w, fir[u]};
  fir[u] = o;
}
int sz[N], son[N], dep[N], ans[N];
void dfs1(int u) {
  sz[u] = 1;
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    a[v] = a[u] ^ e[i].w;
    dep[v] = dep[u] + 1;
    dfs1(v);
    sz[u] += sz[v];
    if (sz[son[u]] < sz[v]) son[u] = v;
  }
}
int f[1 << 22];
void getf(int u) {
  f[a[u]] = max(f[a[u]], dep[u]);
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    getf(v);
  }
}
void clrf(int u) {
  f[a[u]] = -inf;
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    clrf(v);
  }
}
void merge(int u, int S) {
  ans[S] = max(ans[S], f[a[u]] + dep[u] - 2 * dep[S]);
  for (int i = 0; i < 22; ++i)
    if (f[a[u] ^ (1 << i)])
      ans[S] = max(ans[S], f[a[u] ^ (1 << i)] + dep[u] - 2 * dep[S]);
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    merge(v, S);
  }
}
void dfs2(int u) {
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (v == son[u]) continue;
    dfs2(v);
    ans[u] = max(ans[u], ans[v]);
    clrf(v);
  }
  if (son[u]) dfs2(son[u]), ans[u] = max(ans[u], ans[son[u]]);
  ans[u] = max(ans[u], f[a[u]] - dep[u]);
  for (int i = 0; i < 22; ++i)
    ans[u] = max(ans[u], f[a[u] ^ (1 << i)] - dep[u]);
  f[a[u]] = max(f[a[u]], dep[u]);
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (v != son[u]) merge(v, u), getf(v);
  }
}
int main() {
  memset(f, -0x3f, sizeof f);
  n = read();
  for (int(i) = (2); (i) <= (n); ++(i)) {
    fa[i] = read();
    char c;
    scanf(" %c", &c);
    add(fa[i], i, 1 << c - 'a');
  }
  dep[1] = 1;
  dfs1(1);
  dfs2(1);
  for (int(i) = (1); (i) <= (n); ++(i)) printf("%d ", ans[i]);
  puts("");
  return 0;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f * x;
}
