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 + 1000;
int siz[maxn], son[maxn], dep[maxn], flag = 0;
int xor_sum[maxn];
int cnt[1 << 22];
int ans[maxn];
vector<pair<int, int> > g[maxn];
void predfs(int u, int fa) {
  siz[u] = 1;
  dep[u] = dep[fa] + 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    int k = g[u][i].second;
    if (v == fa) continue;
    xor_sum[v] = xor_sum[u] ^ k;
    predfs(v, u);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) {
      son[u] = v;
    }
  }
}
void cal(int u, int fa, int lca, int val) {
  if (cnt[xor_sum[u]])
    ans[lca] = max(ans[lca], cnt[xor_sum[u]] + dep[u] - 2 * dep[lca]);
  for (int i = 0; i <= 21; i++)
    if (cnt[xor_sum[u] ^ (1 << i)])
      ans[lca] =
          max(ans[lca], cnt[xor_sum[u] ^ (1 << i)] + dep[u] - 2 * dep[lca]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == fa || v == flag) continue;
    cal(v, u, lca, val);
  }
}
void add(int u, int fa, int val) {
  cnt[xor_sum[u]] = max(cnt[xor_sum[u]], dep[u]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == fa || v == flag) continue;
    add(v, u, val);
  }
}
void del(int u, int fa, int val) {
  cnt[xor_sum[u]] = 0;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == fa || v == flag) continue;
    del(v, u, val);
  }
}
void dfs(int u, int fa, bool keep) {
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == fa || v == son[u]) continue;
    dfs(v, u, 0);
    ans[u] = max(ans[u], ans[v]);
  }
  if (son[u]) {
    dfs(son[u], u, 1);
    flag = son[u];
    ans[u] = max(ans[u], ans[son[u]]);
  }
  cnt[xor_sum[u]] = max(cnt[xor_sum[u]], dep[u]);
  ans[u] = max(ans[u], cnt[xor_sum[u]] - dep[u]);
  for (int i = 0; i <= 21; i++)
    if (cnt[xor_sum[u] ^ (1 << i)])
      ans[u] = max(ans[u], cnt[xor_sum[u] ^ (1 << i)] - dep[u]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == fa || v == flag) continue;
    cal(v, u, u, 1);
    add(v, u, 1);
  }
  flag = 0;
  if (keep == 0) {
    del(u, fa, -1);
  }
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    char str;
    scanf("%d %c", &x, &str);
    g[x].push_back({i, (1 << (str - 'a'))});
    g[i].push_back({x, (1 << (str - 'a'))});
  }
  predfs(1, 0);
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
  return 0;
}
