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;
template <class T>
void print(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void qr(T &n) {
  n = 0;
  register char c = getchar();
  long long sgn = 1;
  while (c > '9' || c < '0') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    n = (n << 3) + (n << 1) + (c ^ 0x30);
    c = getchar();
  }
  n *= sgn;
}
inline char qrc() {
  register char c = getchar();
  while (c < 'a' || c > 'z') c = getchar();
  return c;
}
const long long MX = 5e5 + 10;
vector<long long> E[MX];
long long ans[MX];
long long son[MX];
long long a[MX];
long long f[1 << 22];
long long depth[MX];
long long children[MX];
void dfs1(long long x) {
  ans[x] = -0x3f3f3f3f;
  children[x] = 1;
  for (auto y : E[x]) {
    depth[y] = depth[x] + 1;
    a[y] ^= a[x];
    dfs1(y);
    children[x] += children[y];
    if (children[y] > children[son[x]]) son[x] = y;
  }
}
void remove(long long x) {
  f[a[x]] = -0x3f3f3f3f;
  for (auto i : E[x]) remove(i);
}
void modify(long long x, long long fa) {
  ans[fa] = max(ans[fa], f[a[x]] + depth[x] - (depth[fa] << 1));
  for (auto i = 0; i < 22; i++)
    ans[fa] = max(ans[fa], f[a[x] ^ (1 << i)] + depth[x] - (depth[fa] << 1));
  for (auto i : E[x]) modify(i, fa);
}
void insert(long long x) {
  f[a[x]] = max(f[a[x]], depth[x]);
  for (auto i : E[x]) insert(i);
}
void dfs2(long long x) {
  ans[x] = 0;
  for (auto i : E[x])
    if (i != son[x]) dfs2(i), remove(i);
  if (son[x]) dfs2(son[x]);
  f[a[x]] = max(f[a[x]], depth[x]);
  for (auto i : E[x])
    if (i != son[x]) modify(i, x), insert(i);
  ans[x] = max(ans[x], f[a[x]] - depth[x]);
  for (auto i = 0; i < 22; i++)
    ans[x] = max(ans[x], f[a[x] ^ (1 << i)] - depth[x]);
  for (auto i : E[x]) ans[x] = max(ans[x], ans[i]);
}
signed main() {
  long long n;
  qr(n);
  for (auto i = 0; i < (1 << 22); i++) f[i] = -0x3f3f3f3f;
  for (auto i = 2; i <= n; i++) {
    long long p;
    qr(p);
    char c = qrc();
    E[p].push_back(i);
    a[i] = 1 << (c - 'a');
  }
  dfs1(1);
  dfs2(1);
  for (auto i = 1; i <= n; i++) printf("%lld%c", ans[i], " \n"[i == n]);
  return 0;
}
