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>
#pragma GCC optimize(2)
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const long double eps = 1e-9;
const int mod = 1e9 + 7;
const int maxn = 20;
const int N = 5e5 + 100;
const int M = (1 << 16) + 10;
const long long mm = (1LL << 32);
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  x = f ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  T y = 1;
  int len = 1;
  for (; y <= x / 10; y *= 10) ++len;
  for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
long long qpow(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
int n;
char c[N];
struct edge {
  int to, next;
} e[N << 1];
int h[N], tot;
inline void add(int u, int v) {
  e[++tot] = (edge){v, h[u]};
  h[u] = tot;
  e[++tot] = (edge){u, h[v]};
  h[v] = tot;
}
int siz[N], sum[N], son[N], dfn[N], low[N], Time, ord[N], dep[N];
void dfs(int u, int fa) {
  ord[dfn[u] = ++Time] = u;
  siz[u] = 1;
  dep[u] = dep[fa] + 1;
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa) {
      sum[v] = sum[u] ^ (1 << (c[v] - 'a'));
      dfs(v, u);
      siz[u] += siz[v];
      if (siz[v] > siz[son[u]]) son[u] = v;
    }
  low[u] = Time;
}
int f[1 << 22], ans[N];
inline void chkmax(int &a, int b) {
  if (a < b) a = b;
}
void Add(int u, int fa) {
  for (int i = dfn[u]; i <= low[u]; ++i) {
    if (f[sum[ord[i]]])
      chkmax(ans[fa], f[sum[ord[i]]] + dep[ord[i]] - (dep[fa] << 1));
    for (int j = 0; j < 22; ++j) {
      if (f[sum[ord[i]] ^ (1 << j)])
        chkmax(ans[fa],
               f[sum[ord[i]] ^ (1 << j)] + dep[ord[i]] - (dep[fa] << 1));
    }
  }
  for (int i = dfn[u]; i <= low[u]; ++i) chkmax(f[sum[ord[i]]], dep[ord[i]]);
}
void Del(int u) {
  for (int i = dfn[u]; i <= low[u]; ++i) f[sum[ord[i]]] = 0;
}
void dsu(int u, int fa) {
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa && v != son[u]) dsu(v, u), Del(v), chkmax(ans[u], ans[v]);
  if (son[u]) dsu(son[u], u), chkmax(ans[u], ans[son[u]]);
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != son[u] && v != fa) Add(v, u);
  if (f[sum[u]]) chkmax(ans[u], f[sum[u]] - dep[u]);
  for (int i = 0; i < 22; ++i)
    if (f[sum[u] ^ (1 << i)]) chkmax(ans[u], f[sum[u] ^ (1 << i)] - dep[u]);
  chkmax(f[sum[u]], dep[u]);
}
int main() {
  read(n);
  for (int i = 2; i <= n; ++i) {
    int x;
    read(x);
    add(x, i);
    c[i] = getchar();
    while (c[i] < 'a' || c[i] > 'v') c[i] = getchar();
  }
  dfs(1, 0);
  dsu(1, 0);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
