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 int read() {
  int x = 0, f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(int x) {
  write(x);
  puts("");
}
const int INF = 1e9, N = 5e5 + 5;
struct edge {
  int link, next, val;
} e[N];
int tot, n, head[N];
inline void add_edge(int u, int v, int w) {
  e[++tot] = (edge){v, head[u], w};
  head[u] = tot;
}
inline void init() {
  n = read();
  for (int i = 2; i <= n; i++) {
    int x = read(), c = getchar() - 'a';
    add_edge(x, i, c);
  }
}
int D[N], dep[N], heavy[N], sz[N];
void Dfs(int u) {
  sz[u] = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    D[v] = D[u] ^ (1 << e[i].val);
    dep[v] = dep[u] + 1;
    Dfs(v);
    sz[u] += sz[v];
    if (!heavy[u] || sz[heavy[u]] < sz[v]) {
      heavy[u] = v;
    }
  }
}
int mx, col[1 << 22], ans[N], now;
inline void cal(int u) {
  if (col[D[u]]) mx = max(mx, dep[u] + col[D[u]] - now);
  for (int i = 0; i < 22; i++)
    if (col[(1 << i) ^ D[u]]) mx = max(mx, dep[u] + col[(1 << i) ^ D[u]] - now);
}
inline void up(int u) { col[D[u]] = max(dep[u], col[D[u]]); }
void calc(int u) {
  cal(u);
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    calc(v);
  }
}
void upd(int u) {
  up(u);
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    upd(v);
  }
}
void clear(int u) {
  col[D[u]] = 0;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    clear(v);
  }
}
void dfs(int u, bool keep) {
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    if (v != heavy[u]) {
      dfs(v, 0);
    }
  }
  if (heavy[u]) dfs(heavy[u], 1);
  now = dep[u] << 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    mx = max(ans[v], mx);
  }
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    if (v != heavy[u]) {
      calc(v);
      upd(v);
    }
  }
  cal(u);
  up(u);
  ans[u] = mx;
  if (!keep) {
    clear(u);
    mx = 0;
  }
}
inline void solve() {
  Dfs(1);
  dfs(1, 1);
  for (int i = 1; i <= n; i++) write(ans[i]), putchar(' ');
}
int main() {
  init();
  solve();
  return 0;
}
