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 int read() {
  int nm = 0, fh = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') fh = -1;
  for (; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
  return nm * fh;
}
int n, tot, to[500020 << 1], len[500020 << 1], nt[500020 << 1], fs[500020];
int dep[500020], dis[500020], sz[500020], fa[500020], mxs[500020], top,
    ans[500020], mx[500020 << 6];
int num[500020], N;
pair<int, int> sta[500020];
vector<int> clr;
inline void link(int u, int v, int w) {
  to[++tot] = v, len[tot] = w, nt[tot] = fs[u], fs[u] = tot;
}
inline void dfs(int u) {
  dep[u] = dep[fa[u]] + 1, sz[u] = 1;
  for (int i = fs[u]; i; i = nt[i])
    if (to[i] ^ fa[u]) {
      dis[to[i]] = dis[u] ^ (1 << len[i]), dfs(to[i]), sz[u] += sz[to[i]];
      if (sz[to[i]] > sz[mxs[u]]) mxs[u] = to[i];
    }
}
inline void getdis(int u) {
  sta[++top] = make_pair(dep[u], dis[u]);
  for (int i = fs[u]; i; i = nt[i])
    if (to[i] ^ fa[u]) getdis(to[i]);
}
inline void dfst(int u, int flag = 0) {
  for (int i = fs[u]; i; i = nt[i])
    if ((to[i] ^ fa[u]) && (to[i] ^ mxs[u]))
      dfst(to[i], 1), ans[u] = max(ans[u], ans[to[i]]);
  if (mxs[u]) dfst(mxs[u], 0), ans[u] = max(ans[u], ans[mxs[u]]);
  for (int i = fs[u]; i; i = nt[i])
    if ((to[i] ^ fa[u]) && (to[i] ^ mxs[u])) {
      top = 0, getdis(to[i]);
      for (int j = 1; j <= top; j++)
        for (int k = 1; k <= N; k++)
          ans[u] = max(ans[u], mx[sta[j].second ^ num[k]] + sta[j].first -
                                   (dep[u] << 1));
      for (int j = 1; j <= top; j++)
        mx[sta[j].second] = max(mx[sta[j].second], sta[j].first),
        clr.push_back(sta[j].second);
    }
  for (int i = 1; i <= N; i++)
    ans[u] = max(ans[u], mx[dis[u] ^ num[i]] - dep[u]);
  mx[dis[u]] = max(mx[dis[u]], dep[u]), clr.push_back(dis[u]);
  if (flag) {
    for (int i = 0, TP = clr.size(); i < TP; i++) mx[clr[i]] = -1000000000;
    clr.clear();
  }
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) {
    fa[i] = read();
    char ch[15];
    scanf("%s", ch + 1), link(fa[i], i, ch[1] - 'a');
  }
  for (int i = 0; i < 22; i++) num[++N] = (1 << i);
  num[++N] = 0;
  memset(mx, -0x3f, sizeof(mx)), dfs(1), dfst(1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  puts("");
  return 0;
}
