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>
const int S = 500005;
int n, h[S], nx[S], v[S], eg = 1, w[S], fa[S], t[1 << 22], e[S], s[S], dep[S],
                          f[S], st[S], ans, res[S];
inline int ma(int a, int b) { return a > b ? a : b; }
inline void egadd(int uu, int vv, int ww) {
  nx[++eg] = h[uu];
  h[uu] = eg;
  v[eg] = vv;
  w[eg] = ww;
}
void dfs_1(int x) {
  s[x] = 1;
  for (int i = h[x]; i; i = nx[i]) {
    dep[v[i]] = dep[x] + 1;
    f[v[i]] = f[x] ^ (1 << w[i]);
    dfs_1(v[i]);
    s[x] += s[v[i]];
    if (s[v[i]] > s[e[x]]) e[x] = v[i];
  }
}
void clear(int x) {
  t[f[x]] = 0;
  for (int i = h[x]; i; i = nx[i]) clear(v[i]);
}
void dfs_3(int x) {
  st[++st[0]] = x;
  if (t[f[x]]) ans = ma(ans, t[f[x]] + dep[x]);
  for (int i = 0; i < 22; ++i)
    if (t[f[x] ^ (1 << i)]) ans = ma(ans, t[f[x] ^ (1 << i)] + dep[x]);
  for (int i = h[x]; i; i = nx[i]) dfs_3(v[i]);
}
void dfs_2(int x) {
  for (int i = h[x]; i; i = nx[i])
    if (v[i] != e[x]) dfs_2(v[i]), clear(v[i]);
  if (e[x]) dfs_2(e[x]);
  ans = 0;
  if (t[f[x]]) ans = t[f[x]] + dep[x];
  for (int i = 0; i < 22; ++i)
    if (t[f[x] ^ (1 << i)]) ans = ma(ans, t[f[x] ^ (1 << i)] + dep[x]);
  t[f[x]] = ma(t[f[x]], dep[x]);
  st[0] = 0;
  for (int i = h[x]; i; i = nx[i])
    if (v[i] != e[x]) {
      st[0] = 0;
      dfs_3(v[i]);
      for (int i = st[0]; i; --i) t[f[st[i]]] = ma(t[f[st[i]]], dep[st[i]]);
    }
  if (ans) ans -= dep[x] << 1;
  for (int i = h[x]; i; i = nx[i]) ans = ma(ans, res[v[i]]);
  if (ans) res[x] = ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    char c;
    scanf("%d %c", fa + i, &c);
    egadd(fa[i], i, c - 'a');
  }
  dep[1] = 1;
  dfs_1(1);
  dfs_2(1);
  for (int i = 1; i <= n; ++i) printf("%d ", res[i]);
  return 0;
}
