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 N = 5e5 + 5;
int n, head[N], cnt, fa[N], dp[N], dep[N], sz[N], son[N], zt[N], dfn[N], idx,
    idfn[N];
int buc[1 << 23];
struct edge {
  int to, nxt, w;
} e[N];
void dfs(int u) {
  idfn[dfn[u] = ++idx] = u;
  sz[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    dep[e[i].to] = dep[u] + 1;
    zt[e[i].to] = zt[u] ^ (1 << e[i].w);
    dfs(e[i].to);
    sz[u] += sz[e[i].to];
    if (!son[u] || sz[son[u]] < sz[e[i].to]) son[u] = e[i].to;
  }
}
void dfs2(int u, bool tg) {
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != son[u]) dfs2(e[i].to, 0), dp[u] = max(dp[u], dp[e[i].to]);
  int res = 0;
  if (son[u]) {
    dfs2(son[u], 1), dp[u] = max(dp[u], dp[son[u]]);
    res = max(res, dep[u] + buc[zt[u]]);
    for (int i = 0; i < 22; ++i) res = max(res, dep[u] + buc[zt[u] ^ (1 << i)]);
  }
  buc[zt[u]] = max(buc[zt[u]], dep[u]);
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != son[u]) {
      int l = dfn[e[i].to], r = l + sz[e[i].to] - 1;
      for (int x = l; x <= r; ++x) {
        int s = zt[idfn[x]];
        res = max(res, dep[idfn[x]] + buc[s]);
        for (int y = 0; y < 22; ++y)
          res = max(res, dep[idfn[x]] + buc[s ^ (1 << y)]);
      }
      for (int x = l; x <= r; ++x) {
        int s = zt[idfn[x]];
        buc[s] = max(buc[s], dep[idfn[x]]);
      }
    }
  dp[u] = max(dp[u], res - 2 * dep[u]);
  if (!tg)
    for (int i = dfn[u]; i < dfn[u] + sz[u]; ++i) buc[zt[idfn[i]]] = -1e8;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (int i = 0; i < 1 << 23; ++i) buc[i] = -1e8;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    char c;
    cin >> fa[i] >> c;
    e[++cnt] = (edge){i, head[fa[i]], c - 'a'}, head[fa[i]] = cnt;
  }
  dfs(1);
  dfs2(1, 0);
  for (int i = 1; i <= n; ++i) cout << dp[i] << ' ';
  return 0;
}
