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;
struct Edge {
  char c;
  int to, next;
} E[500100 << 1];
int head[500100], dep[500100], cnt;
int N, sz[500100], son[500100], vis[500100], ans[500100], dis[500100],
    f[5001000];
inline void add(int u, int v, char c) {
  E[++cnt].to = v, E[cnt].c = c;
  E[cnt].next = head[u], head[u] = cnt;
  E[++cnt].to = u, E[cnt].c = c;
  E[cnt].next = head[v], head[v] = cnt;
}
void dfs(int u, int fa) {
  sz[u] = 1, dep[u] = dep[fa] + 1;
  for (int k = head[u]; k; k = E[k].next) {
    if (E[k].to == fa) continue;
    dis[E[k].to] = dis[u] ^ (1 << (int)(E[k].c - 'a'));
    dfs(E[k].to, u), sz[u] += sz[E[k].to];
    if (sz[E[k].to] > sz[son[u]]) son[u] = E[k].to;
  }
}
void _delete(int u, int fa) {
  f[dis[u]] = 0;
  for (int k = head[u]; k; k = E[k].next)
    if (E[k].to != fa && !vis[E[k].to]) _delete(E[k].to, u);
}
void calc(int u, int fa, int& ans, int d) {
  if (f[dis[u]]) ans = max(ans, f[dis[u]] + dep[u] - 2 * d);
  for (int i = 0; i <= 21; ++i)
    if (f[dis[u] ^ (1 << i)])
      ans = max(ans, f[dis[u] ^ (1 << i)] + dep[u] - 2 * d);
  for (int k = head[u]; k; k = E[k].next)
    if (E[k].to != fa && !vis[E[k].to]) calc(E[k].to, u, ans, d);
}
void update(int u, int fa) {
  f[dis[u]] = max(f[dis[u]], dep[u]);
  for (int k = head[u]; k; k = E[k].next)
    if (E[k].to != fa && !vis[E[k].to]) update(E[k].to, u);
}
void dfs(int u, int fa, int mk) {
  for (int k = head[u]; k; k = E[k].next) {
    if (E[k].to == fa || E[k].to == son[u]) continue;
    dfs(E[k].to, u, 0), ans[u] = max(ans[u], ans[E[k].to]);
  }
  if (son[u])
    dfs(son[u], u, 1), vis[son[u]] = 1, ans[u] = max(ans[u], ans[son[u]]);
  if (f[dis[u]]) ans[u] = max(ans[u], f[dis[u]] + dep[u] - 2 * dep[u]);
  for (int i = 0; i <= 21; ++i)
    if (f[dis[u] ^ (1 << i)])
      ans[u] = max(ans[u], f[dis[u] ^ (1 << i)] + dep[u] - 2 * dep[u]);
  f[dis[u]] = max(f[dis[u]], dep[u]);
  for (int k = head[u]; k; k = E[k].next)
    if (E[k].to != son[u] && E[k].to != fa)
      calc(E[k].to, u, ans[u], dep[u]), update(E[k].to, u);
  vis[son[u]] = 0;
  if (!mk) _delete(u, fa);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0), cout.tie(0), cin >> N;
  int i, u;
  char c;
  for (i = 2; i <= N; ++i) cin >> u >> c, add(i, u, c);
  dfs(1, 0);
  dfs(1, 0, 0);
  for (i = 1; i <= N; ++i) cout << ans[i] << " ";
  return 0;
}
