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 void read(int &x) {
  char c = getchar();
  x = 0;
  while (!isdigit(c) && !isalpha(c)) c = getchar();
  if (isalpha(c)) return void(x = c - 'a');
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
}
const int N = 5e5 + 5, SZ = 22;
int n, vv, ww;
int e, head[N], to[N << 1], val[N << 1], nxt[N << 1];
inline void add(int u, int v, int w) {
  to[++e] = v;
  val[e] = w;
  nxt[e] = head[u];
  head[u] = e;
}
inline void add_edge(int u, int v, int w) {
  add(u, v, w);
  add(v, u, w);
}
int sz[N], son[N], f[1 << 22 | 5], dep[N], Son, Max, ans[N], cur[N], s[N];
inline void print(int x) {
  for (int i = 0; i <= 21; i++) cout << ((x >> i) & 1);
  cout << " ";
}
inline void dfs1(int u, int fa) {
  sz[u] = 1;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) {
      int v = to[i], w = val[i];
      s[v] = s[u] ^ (1 << w);
      dep[v] = dep[u] + 1;
      dfs1(v, u);
      sz[u] += sz[v];
      if (sz[v] > sz[son[u]]) son[u] = v;
    }
}
inline void calc(int u, int fa) {
  if (f[s[u]]) Max = max(Max, f[s[u]] + dep[u]);
  for (int i = 1; i <= (1 << 21); i <<= 1)
    if (f[i ^ s[u]]) Max = max(Max, f[i ^ s[u]] + dep[u]);
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) calc(to[i], u);
}
inline void update(int u, int fa) {
  f[s[u]] = max(f[s[u]], dep[u]);
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) update(to[i], u);
}
inline void get_Max(int u, int fa) {
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa && to[i] != Son) {
      calc(to[i], u);
      update(to[i], u);
    }
}
inline void clear(int u, int fa) {
  f[s[u]] = 0;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) clear(to[i], u);
}
inline void dfs2(int u, int fa, bool keep) {
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa && to[i] != son[u]) dfs2(to[i], u, false);
  if (son[u]) dfs2(son[u], u, true);
  Son = son[u];
  f[s[u]] = max(f[s[u]], dep[u]);
  get_Max(u, fa);
  ans[u] = max(f[s[u]] - dep[u], Max - 2 * dep[u]);
  for (int i = 1; i <= (1 << 21); i <<= 1)
    ans[u] = max(ans[u], f[i ^ s[u]] - dep[u]);
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) ans[u] = max(ans[u], ans[to[i]]);
  Son = Max = 0;
  if (!keep) clear(u, fa);
}
int main() {
  read(n);
  for (int uu = 2; uu <= n; uu++) {
    read(vv);
    read(ww);
    add_edge(uu, vv, ww);
  }
  dfs1(1, 0);
  dfs2(1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
