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 = 500000, maxs = 1 << 22;
int n, si[maxn + 5], dep[maxn + 5], sum[maxn + 5], SH[maxn + 5];
int E, lnk[maxn + 5], son[maxn + 5], nxt[maxn + 5], w[maxn + 5];
int now, MAX, MD[maxs + 5], ans[maxn + 5];
bool vis[maxn + 5];
inline char getlwr() {
  char ch = getchar();
  while (!islower(ch)) ch = getchar();
  return ch;
}
void HLD(int x) {
  si[x] = 1;
  for (int j = lnk[x]; j; j = nxt[j]) {
    dep[son[j]] = dep[x] + 1;
    sum[son[j]] = sum[x] ^ (1 << w[j]);
    HLD(son[j]);
    si[x] += si[son[j]];
    if (si[son[j]] > si[SH[x]]) SH[x] = son[j];
  }
}
inline void getMAX(int x) {
  if (MD[sum[x]]) MAX = max(MAX, dep[x] + MD[sum[x]] - (now << 1));
  for (int j = 0; j < 22; j++)
    if (MD[sum[x] ^ (1 << j)])
      MAX = max(MAX, dep[x] + MD[sum[x] ^ (1 << j)] - (now << 1));
}
void Update(int x) {
  getMAX(x);
  for (int j = lnk[x]; j; j = nxt[j]) Update(son[j]);
}
inline void Fix(int x) {
  if (dep[x] > MD[sum[x]]) MD[sum[x]] = dep[x];
}
void Insert(int x) {
  Fix(x);
  for (int j = lnk[x]; j; j = nxt[j]) Insert(son[j]);
}
void Delete(int x) {
  MD[sum[x]] = 0;
  for (int j = lnk[x]; j; j = nxt[j]) Delete(son[j]);
}
void Solve(int x, bool fl = true) {
  for (int j = lnk[x]; j; j = nxt[j])
    if (son[j] != SH[x]) Solve(son[j], false);
  if (SH[x]) Solve(SH[x], true);
  now = dep[x];
  for (int j = lnk[x]; j; j = nxt[j]) ans[x] = max(ans[x], ans[son[j]]);
  for (int j = lnk[x]; j; j = nxt[j])
    if (son[j] != SH[x]) Update(son[j]), Insert(son[j]);
  getMAX(x);
  Fix(x);
  ans[x] = max(ans[x], MAX);
  if (!fl) Delete(x), MAX = 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 2, x; i <= n; i++)
    scanf("%d", &x), son[++E] = (i), w[E] = (getlwr() - 'a'), nxt[E] = lnk[x],
                     lnk[x] = E;
  HLD(1);
  Solve(1);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
