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;
long long gi() {
  long long ret = 0;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  char c = ch == '-' ? getchar() : ch;
  while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
  return ch == '-' ? -ret : ret;
}
const int N = 500000 + 10;
int n, st[N], pt[N << 1], nxt[N << 1], w[N << 1];
int sz[N], bson[N], fa[N], ans[N], dfn[N], ed[N], q[N], xr[N], dep[N],
    cnt[4194304], ent, dnt;
void link(int u, int v, int _w) {
  pt[++ent] = v;
  nxt[ent] = st[u];
  st[u] = ent;
  w[ent] = _w;
  pt[++ent] = u;
  nxt[ent] = st[v];
  st[v] = ent;
  w[ent] = _w;
}
void dfs(int x) {
  sz[x] = 1;
  q[++dnt] = x;
  dfn[x] = dnt;
  for (int i = st[x]; i; i = nxt[i])
    if (pt[i] != fa[x]) {
      fa[pt[i]] = x;
      xr[pt[i]] = xr[x] ^ w[i];
      dep[pt[i]] = dep[x] + 1;
      dfs(pt[i]);
      sz[x] += sz[pt[i]];
      if (sz[pt[i]] > sz[bson[x]]) bson[x] = pt[i];
    }
  ed[x] = dnt;
}
void upd(int &a, int v, int d) {
  a = max(a, d + cnt[v]);
  for (int i = 0; i < 22; i += 1) a = max(a, d + cnt[v ^ (1 << i)]);
}
void solve(int x, int f) {
  for (int i = st[x]; i; i = nxt[i])
    if (pt[i] != fa[x] && pt[i] != bson[x]) solve(pt[i], 0);
  if (bson[x]) solve(bson[x], 1);
  ans[x] -= 2 * dep[x];
  upd(ans[x], xr[x], dep[x]);
  cnt[xr[x]] = max(cnt[xr[x]], dep[x]);
  for (int i = st[x]; i; i = nxt[i])
    if (pt[i] != fa[x] && pt[i] != bson[x]) {
      for (int j = dfn[pt[i]]; j <= ed[pt[i]]; j += 1)
        upd(ans[x], xr[q[j]], dep[q[j]]);
      for (int j = dfn[pt[i]]; j <= ed[pt[i]]; j += 1)
        cnt[xr[q[j]]] = max(cnt[xr[q[j]]], dep[q[j]]);
    }
  ans[x] -= 2 * dep[x];
  for (int i = st[x]; i; i = nxt[i])
    if (pt[i] != fa[x]) ans[x] = max(ans[x], ans[pt[i]]);
  if (!f) {
    for (int i = dfn[x]; i <= ed[x]; i += 1) cnt[xr[q[i]]] = -1e9;
  }
}
int main() {
  n = gi();
  int u;
  char s[10];
  for (int i = 2; i <= n; i += 1) {
    u = gi();
    scanf("%s", s);
    link(u, i, 1 << (s[0] - 'a'));
  }
  memset(cnt, -60, sizeof cnt);
  dfs(1);
  solve(1, 0);
  for (int i = 1; i <= n; i += 1) printf("%d ", max(0, ans[i]));
  return 0;
}
