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 = 5e5 + 10;
int sz[maxn], dep[maxn], mask[maxn], ans[maxn];
vector<pair<int, int>> g[maxn];
void get_sz(int u, int f) {
  sz[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first, c = g[u][i].second;
    if (v == f) continue;
    dep[v] = dep[u] + 1;
    mask[v] = mask[u] ^ (1 << c);
    get_sz(v, u);
    sz[u] += sz[v];
  }
}
int curans, curd;
int ml[1 << 22];
void doupd(int val, int du) {
  if (ml[val] != -1) curans = max(curans, ml[val] + du - 2 * curd);
  for (int i = 0; i < 22; i++)
    if (ml[val ^ (1 << i)] != -1)
      curans = max(curans, ml[val ^ (1 << i)] + du - 2 * curd);
}
void upd(int u, int f) {
  doupd(mask[u], dep[u]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v != f) upd(v, u);
  }
}
void ins(int u, int f, int flag) {
  int val = mask[u];
  if (flag)
    ml[val] = max(ml[val], dep[u]);
  else
    ml[val] = -1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v != f) ins(v, u, flag);
  }
}
void dfs(int u, int f, int k) {
  int bc = -1, bsz = 0;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == f) continue;
    if (sz[v] > bsz) bc = v, bsz = sz[v];
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == f || v == bc) continue;
    dfs(v, u, 0);
  }
  if (bc != -1) dfs(bc, u, 1);
  curd = dep[u];
  curans = 0;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v == f) continue;
    ans[u] = max(ans[u], ans[v]);
    if (v != bc) upd(v, u), ins(v, u, 1);
  }
  doupd(mask[u], dep[u]);
  ml[mask[u]] = max(ml[mask[u]], dep[u]);
  ans[u] = max(ans[u], curans);
  if (!k) ins(u, f, 0);
}
char str[4];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int v, c;
    scanf("%d%s", &v, str);
    g[i].push_back(make_pair(v, str[0] - 'a'));
    g[v].push_back(make_pair(i, str[0] - 'a'));
  }
  get_sz(1, 0);
  memset(ml, -1, sizeof(ml));
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
