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 = 500010;
int head[maxn], Next[maxn * 2], ver[maxn * 2], edge[maxn * 2];
int cnt[maxn], sz[maxn], son[maxn], tot;
const int S = 'v' - 'a' + 1, INF = 1e9;
int lca_deep, skip, now;
int dp[maxn], re[1 << S], a[maxn], deep[maxn];
void add(int x, int y, int z) {
  ver[++tot] = y;
  edge[tot] = z;
  Next[tot] = head[x];
  head[x] = tot;
}
void get_son(int x, int f = 0) {
  sz[x] = 1;
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y == f) continue;
    a[y] = a[x] ^ edge[i];
    deep[y] = deep[x] + 1;
    get_son(y, x);
    sz[x] += sz[y];
    if (sz[y] > sz[son[x]]) son[x] = y;
  }
}
void clr(int x) { re[a[x]] = -INF; }
void change(int x) {
  now = max(now, re[a[x]] + deep[x] - lca_deep * 2);
  for (int i = 0; i < S; i++) {
    now = max(now, re[a[x] ^ (1 << i)] + deep[x] - lca_deep * 2);
  }
}
void maintain(int x) { re[a[x]] = max(re[a[x]], deep[x]); }
template <void (*func)(int)>
void update(int x, int f) {
  func(x);
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y != f && y != skip) update<func>(y, x);
  }
}
void dfs(int x, int f = 0, int kep = 0) {
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y != f && y != son[x]) {
      dfs(y, x);
    }
  }
  if (son[x]) {
    dfs(son[x], x, 1), skip = son[x];
  }
  lca_deep = deep[x];
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y != f) dp[x] = max(dp[x], dp[y]);
  }
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y != f && y != son[x]) {
      update<change>(y, x);
      update<maintain>(y, x);
    }
  }
  change(x), maintain(x);
  dp[x] = max(dp[x], now);
  skip = 0;
  if (!kep) {
    update<clr>(x, f);
    now = -INF;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (1 << S); i++) {
    re[i] = -INF;
  }
  for (int i = 2; i <= n; i++) {
    int x;
    char z[3];
    scanf("%d%s", &x, z);
    add(i, x, 1 << (z[0] - 'a'));
    add(x, i, 1 << (z[0] - 'a'));
  }
  get_son(1);
  dfs(1);
  for (int i = 1; i <= n; i++) printf("%d ", dp[i]);
}
