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 char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
inline void read(int &x) {
  static char c;
  x = 0;
  for (c = get(); c < '0' || c > '9'; c = get())
    ;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
}
const int N = 501010;
const int INF = 1 << 30;
int dfc, n, x, Gcnt;
char c;
struct edge {
  int to, next;
  edge(int t = 0, int n = 0) : to(t), next(n) {}
};
edge G[N << 1];
int head[N], ans[N];
int f[N], dis[1 << 23];
int pre[N], post[N], id[N];
int son[N], size[N], dep[N];
int bin[23];
inline int Max(int a, int b) { return a > b ? a : b; }
inline void AddEdge(int from, int to) {
  G[++Gcnt] = edge(to, head[from]);
  head[from] = Gcnt;
}
void dfs1(int u) {
  pre[u] = ++dfc;
  size[u] = 1;
  int to;
  id[dfc] = u;
  for (int i = head[u]; i; i = G[i].next) {
    to = G[i].to;
    dep[to] = dep[u] + 1;
    dfs1(to);
    size[u] += size[to];
    if (size[son[u]] < size[to]) son[u] = to;
  }
  post[u] = dfc;
}
inline int mxdep(int S) {
  int mx = -INF;
  if (dis[S]) mx = dis[S];
  for (int i = 0; i < 22; i++)
    if (dis[S ^ bin[i]]) mx = Max(mx, dis[S ^ bin[i]]);
  return mx;
}
void dfs(int u, int iw) {
  for (int i = head[u]; i; i = G[i].next)
    if (G[i].to != son[u]) dfs(G[i].to, 1);
  if (son[u]) dfs(son[u], 0);
  for (int i = head[u]; i; i = G[i].next) {
    int to = G[i].to;
    ans[u] = Max(ans[u], ans[to]);
    if (to != son[u]) {
      for (int j = pre[to]; j <= post[to]; j++)
        ans[u] = Max(ans[u], mxdep(f[id[j]]) + dep[id[j]] - dep[u] * 2);
      for (int j = pre[to]; j <= post[to]; j++)
        dis[f[id[j]]] = Max(dis[f[id[j]]], dep[id[j]]);
    }
  }
  dis[f[u]] = Max(dis[f[u]], dep[u]);
  ans[u] = Max(ans[u], mxdep(f[u]) - dep[u]);
  if (iw)
    for (int i = pre[u]; i <= post[u]; i++) dis[f[id[i]]] = 0;
}
int main(void) {
  read(n);
  for (int i = 0; i < 22; i++) bin[i] = 1 << i;
  for (int i = 2; i <= n; i++) {
    read(x);
    c = get();
    f[i] = f[x] ^ bin[c - 'a'];
    AddEdge(x, i);
  }
  dfs1(1);
  dfs(1, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  putchar('\n');
  return 0;
}
