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;
const int maxn = 5e5 + 5;
int size[maxn], dep[maxn], val[maxn], dfn[maxn], hson[maxn], ans[maxn],
    rnk[maxn];
int cnt[(1 << 22) + 4];
struct EDGE {
  int to, next;
  char c;
} edge[maxn << 1];
int head[maxn], tot, num;
void addedge(int u, int v, char c) {
  edge[++tot].next = head[u];
  edge[tot].to = v;
  edge[tot].c = c;
  head[u] = tot;
}
void dfs(int now, int pre) {
  size[now] = 1;
  dep[now] = dep[pre] + 1;
  dfn[now] = ++num;
  rnk[num] = now;
  for (int i = head[now]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to == pre) continue;
    val[to] = val[now] ^ (1 << (edge[i].c - 'a'));
    dfs(to, now);
    size[now] += size[to];
    if (size[to] > size[hson[now]]) hson[now] = to;
  }
}
void cal(int now) {
  if (cnt[val[now]]) ans[now] = max(ans[now], cnt[val[now]] - dep[now]);
  for (int i = 0; i < 22; ++i) {
    if (cnt[val[now] ^ (1 << i)])
      ans[now] = max(ans[now], cnt[val[now] ^ (1 << i)] - dep[now]);
  }
  cnt[val[now]] = max(cnt[val[now]], dep[now]);
  for (int i = head[now]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (dep[to] < dep[now] || to == hson[now]) continue;
    for (int j = dfn[to]; j <= dfn[to] + size[to] - 1; ++j) {
      int tmp = rnk[j];
      if (cnt[val[tmp]])
        ans[now] = max(ans[now], cnt[val[tmp]] + dep[tmp] - 2 * dep[now]);
      for (int i = 0; i < 22; ++i) {
        if (cnt[val[tmp] ^ (1 << i)])
          ans[now] =
              max(ans[now], cnt[val[tmp] ^ (1 << i)] + dep[tmp] - 2 * dep[now]);
      }
    }
    for (int j = dfn[to]; j <= dfn[to] + size[to] - 1; ++j) {
      int tmp = rnk[j];
      cnt[val[tmp]] = max(cnt[val[tmp]], dep[tmp]);
    }
  }
}
void dfs2(int now, bool heave) {
  for (int i = head[now]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (dep[to] < dep[now] || to == hson[now]) continue;
    dfs2(to, 0);
    ans[now] = max(ans[now], ans[to]);
  }
  if (hson[now]) dfs2(hson[now], 1), ans[now] = max(ans[now], ans[hson[now]]);
  cal(now);
  if (!heave)
    for (int i = dfn[now]; i <= dfn[now] + size[now] - 1; ++i)
      cnt[val[rnk[i]]] = 0;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int to;
    char c;
    scanf("%d %c", &to, &c);
    addedge(i, to, c);
    addedge(to, i, c);
  }
  dfs(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
