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>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
using namespace std;
inline int read() {
  int a = 1, b = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') a = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    b = b * 10 + ch - '0';
    ch = getchar();
  }
  return a * b;
}
const int N = 5e5 + 5, M = 5e6 + 5;
const int INF = 1e8;
vector<pair<int, int> > g[N];
int n, p, dp[N], sz[N], son[N], deep[N], st[N], mx[M];
char c[2];
void get_son(int u, int o) {
  sz[u] = 1;
  deep[u] = deep[o] + 1;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    int w = g[u][i].second;
    st[v] = st[u] ^ (1 << w);
    get_son(v, u);
    if (sz[v] > sz[son[u]]) son[u] = v;
    sz[u] += sz[v];
  }
}
void CAL(int p, int u) {
  if (mx[st[u]] >= 0) dp[p] = max(dp[p], mx[st[u]] + deep[u] - 2 * deep[p]);
  for (int i = 0; i < 22; ++i) {
    if (mx[st[u] ^ (1 << i)] >= 0)
      dp[p] = max(dp[p], mx[st[u] ^ (1 << i)] + deep[u] - 2 * deep[p]);
  }
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    CAL(p, v);
  }
}
void ADD(int u) {
  mx[st[u]] = max(mx[st[u]], deep[u]);
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    ADD(v);
  }
}
void DELETE(int u) {
  if (mx[st[u]] >= 0) mx[st[u]] = -INF;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    DELETE(v);
  }
}
void dfs(int u) {
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (v != son[u]) {
      dfs(v);
      DELETE(v);
    }
  }
  if (son[u]) dfs(son[u]);
  mx[st[u]] = max(mx[st[u]], deep[u]);
  if (mx[st[u]] >= 0) dp[u] = mx[st[u]] - deep[u];
  for (int i = 0; i < 22; ++i) {
    if (mx[st[u] ^ (1 << i)] >= 0)
      dp[u] = max(dp[u], mx[st[u] ^ (1 << i)] - deep[u]);
  }
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    if (v != son[u]) {
      CAL(u, v);
      ADD(v);
    }
  }
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i].first;
    dp[u] = max(dp[u], dp[v]);
  }
}
int main() {
  n = read();
  for (int i = 2; i <= n; ++i) {
    p = read();
    scanf("%s", c);
    g[p].push_back({i, c[0] - 'a'});
  }
  get_son(1, 0);
  for (int i = 0; i < M; ++i) mx[i] = -INF;
  dfs(1);
  for (int i = 1; i <= n; ++i) printf("%d%c", dp[i], " \n"[i == n]);
  return 0;
}
