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 N = 5e5 + 100;
int n = 0;
char ch[N];
vector<int> g[N];
int deep[N], val[N], s[N], l[N], r[N], pos[N], st = 0;
int ans[N];
int Data[20000001];
int get(int u) {
  int sz = 1;
  int maxsz = 0;
  st++;
  l[u] = r[u] = st;
  pos[st] = u;
  for (auto v : g[u]) {
    deep[v] = deep[u] + 1;
    val[v] = val[u] ^ (1 << ch[v] - 'a');
    int szv = get(v);
    r[u] = max(r[u], r[v]);
    if (szv > maxsz) maxsz = szv, s[u] = v;
    sz += szv;
  }
  return sz;
}
void add(int u, bool addon) {
  if (addon)
    Data[val[u]] = max(Data[val[u]], deep[u]);
  else
    Data[val[u]] = -N * 2;
}
int cal(int u) {
  int tans = Data[val[u]];
  for (int i = 0; i <= 22; i++) tans = max(tans, Data[val[u] ^ (1 << i)]);
  return tans + deep[u];
}
void dfs(int u, bool keep) {
  for (auto v : g[u]) {
    if (v == s[u]) continue;
    dfs(v, false);
    ans[u] = max(ans[u], ans[v]);
  }
  if (s[u]) dfs(s[u], true), ans[u] = max(ans[u], ans[s[u]]);
  add(u, true);
  ans[u] = max(ans[u], cal(u) - deep[u] * 2);
  for (auto v : g[u]) {
    if (v == s[u]) continue;
    for (int i = l[v]; i <= r[v]; i++)
      ans[u] = max(ans[u], cal(pos[i]) - deep[u] * 2);
    for (int i = l[v]; i <= r[v]; i++) add(pos[i], true);
  }
  if (keep)
    return;
  else
    for (int i = l[u]; i <= r[u]; i++) add(pos[i], false);
}
void init() {
  memset(Data, 128, sizeof(Data));
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int u;
    scanf("%d", &u);
    g[u].push_back(i);
    cin >> ch[i];
  }
}
int main() {
  init();
  get(1);
  dfs(1, 1);
  for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
}
