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 + 10;
const int L = 22;
const int inf = 1e9 + 10;
int sz[N], h[N], f[N], hvy[N], mx[1 << L], ans[N];
vector<pair<int, int> > adj[N];
void preDFS(int v) {
  for (pair<int, int> e : adj[v]) {
    int u = e.first, w = e.second;
    h[u] = h[v] + 1;
    f[u] = f[v] ^ (1 << w);
    preDFS(u);
    sz[v] += sz[u];
    if (sz[hvy[v]] < sz[u]) hvy[v] = u;
  }
  sz[v]++;
}
void upd(int v, int typ, int ver) {
  if (typ == 1) mx[f[v]] = -inf;
  if (typ == 2) mx[f[v]] = max(mx[f[v]], h[v]);
  if (typ == 3) {
    ans[ver] = max(ans[ver], h[v] + mx[f[v]] - 2 * h[ver]);
    for (int i = 0; i < L; i++)
      ans[ver] = max(ans[ver], h[v] + mx[f[v] ^ (1 << i)] - 2 * h[ver]);
  }
  for (pair<int, int> e : adj[v]) upd(e.first, typ, ver);
}
void DFS(int v) {
  for (pair<int, int> e : adj[v]) {
    if (e.first == hvy[v]) continue;
    DFS(e.first);
    ans[v] = max(ans[v], ans[e.first]);
    upd(e.first, 1, 0);
  }
  if (hvy[v]) {
    DFS(hvy[v]);
    ans[v] = max(ans[v], ans[hvy[v]]);
    ans[v] = max(ans[v], mx[f[v]] - h[v]);
    for (int i = 0; i < L; i++)
      ans[v] = max(ans[v], mx[f[v] ^ (1 << i)] - h[v]);
  }
  mx[f[v]] = max(mx[f[v]], h[v]);
  for (pair<int, int> e : adj[v]) {
    if (e.first == hvy[v]) continue;
    upd(e.first, 3, v);
    upd(e.first, 2, 0);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int p;
    char c;
    cin >> p >> c;
    adj[p].push_back(make_pair(i, c - 'a'));
  }
  preDFS(1);
  fill(mx, mx + (1 << L), -inf);
  DFS(1);
  for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
  return 0;
}
