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;
template <typename T>
inline void read(T &x) {
  register int c = getchar();
  x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
}
template <typename T>
inline void write(T x) {
  static int sta[35];
  register int top = 0;
  if (x < 0) x = -x, putchar('-');
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + '0');
}
template <typename T>
inline void write(T x, const char &c) {
  write(x), putchar(c);
}
const int N = 5e5 + 20;
int n, ans[N], f[1 << 22], son[N], siz[N], dep[N], lin[N];
struct Edge {
  int v;
  char c;
  Edge() {}
  Edge(int V, char C) { v = V, c = C; }
};
inline Edge makeEdge(int V, int C) {
  Edge x(V, C);
  return x;
}
vector<Edge> e[N];
void dfs(int u, int fa) {
  siz[u] = 1;
  dep[u] = dep[fa] + 1;
  int wson = 0, v;
  for (Edge i : e[u]) {
    v = i.v;
    if (v == fa) continue;
    lin[v] = lin[u] ^ (1 << (i.c - 'a'));
    dfs(v, u);
    siz[u] += siz[v];
    if (wson < siz[v]) wson = siz[v], son[u] = v;
  }
}
void clean(int u, int fa) {
  f[lin[u]] = 0;
  for (Edge i : e[u]) {
    if (i.v == fa) continue;
    clean(i.v, u);
  }
}
void give(int u, int fa) {
  f[lin[u]] = max(f[lin[u]], dep[u]);
  for (Edge i : e[u]) {
    if (i.v == fa) continue;
    give(i.v, u);
  }
}
int dfs2(int u, int fa, int lca) {
  int res = 0;
  if (f[lin[u]]) res = max(res, f[lin[u]] + dep[u] - 2 * lca);
  for (register int i = 0; i < 22; i++)
    if (f[lin[u] ^ (1 << i)])
      res = max(res, f[lin[u] ^ (1 << i)] + dep[u] - 2 * lca);
  for (Edge i : e[u]) {
    if (i.v == fa) continue;
    res = max(res, dfs2(i.v, u, lca));
  }
  return res;
}
void dfs1(int u, int fa) {
  for (Edge i : e[u]) {
    if (i.v == fa || i.v == son[u]) continue;
    dfs1(i.v, u);
    ans[u] = max(ans[u], ans[i.v]);
    clean(i.v, u);
  }
  if (son[u]) dfs1(son[u], u), ans[u] = max(ans[u], ans[son[u]]);
  if (f[lin[u]]) ans[u] = max(ans[u], f[lin[u]] - dep[u]);
  for (register int i = 0; i < 22; i++)
    if (f[lin[u] ^ (1 << i)])
      ans[u] = max(ans[u], f[lin[u] ^ (1 << i)] - dep[u]);
  f[lin[u]] = max(f[lin[u]], dep[u]);
  for (Edge i : e[u]) {
    if (i.v == fa || i.v == son[u]) continue;
    ans[u] = max(ans[u], dfs2(i.v, u, dep[u]));
    give(i.v, u);
  }
}
int main() {
  read(n);
  for (register int i = 2, v, c; i <= n; i++) {
    read(v);
    c = getchar();
    for (; c < 'a' || c > 'v'; c = getchar())
      ;
    e[i].push_back(makeEdge(v, c));
    e[v].push_back(makeEdge(i, c));
  }
  dep[0] = -1;
  dfs(1, 0);
  dfs1(1, 0);
  for (register int i = 1; i <= n; i++) write(ans[i], ' ');
  puts("");
  return 0;
}
