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 long long N = 6e5 + 10;
const long long M = 1 << 23 + 1;
const long long big = 1e18;
const long long block = 800;
const long long mod = 1e6;
long long n;
vector<pair<long long, long long> > g[N];
long long pre[N];
long long gl[N];
long long was[M];
long long sz[N];
long long ans[N];
long long mx;
long long dfs(long long v = 1, long long x = 0, long long p = 0) {
  sz[v] = 1;
  pre[v] = x;
  gl[v] = gl[p] + 1;
  for (auto u : g[v]) sz[v] += dfs(u.first, x ^ (1 << u.second), v);
  return sz[v];
}
void pere(long long v, long long p) {
  if (was[pre[v]]) mx = max(mx, was[pre[v]] + gl[v] - 2 * gl[p]);
  for (int i = 0; i < 23; i++) {
    long long z = 1 << i;
    if (was[pre[v] ^ z]) mx = max(mx, was[pre[v] ^ z] + gl[v] - 2 * gl[p]);
  }
  for (auto u : g[v]) pere(u.first, p);
}
void add(long long v) {
  was[pre[v]] = max(was[pre[v]], gl[v]);
  for (auto u : g[v]) add(u.first);
}
void del(long long v) {
  was[pre[v]] = 0;
  for (auto u : g[v]) del(u.first);
}
void STL(long long v = 1, bool clr = 1) {
  pair<long long, long long> zh = {-1, 0};
  for (auto u : g[v]) {
    zh = max((pair<long long, long long>){sz[u.first], u.first}, zh);
  }
  for (auto u : g[v]) {
    if (zh.second != u.first) STL(u.first);
  }
  if (zh.second) {
    STL(zh.second, 0);
    for (auto u : g[v])
      if (zh.second != u.first) {
        pere(u.first, v);
        add(u.first);
      }
  }
  was[pre[v]] = max(was[pre[v]], gl[v]);
  mx = max(mx, was[pre[v]] - gl[v]);
  for (int i = 0; i < 23; i++) {
    long long z = 1 << i;
    if (was[pre[v] ^ z]) mx = max(mx, was[pre[v] ^ z] - gl[v]);
  }
  for (auto u : g[v]) ans[v] = max(ans[v], ans[u.first]);
  ans[v] = max(mx, ans[v]);
  if (clr) del(v);
  mx = 0;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    long long a;
    char b;
    cin >> a >> b;
    g[a].push_back({i, b - 'a'});
  }
  dfs();
  STL();
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
}
