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 = 500005;
int mp[(1 << 22)];
vector<pair<int, char> > g[N];
int ptr, sz[N], dep[N], vert[N], st[N], en[N], ans[N], mask[N];
void dfs(int v, int p) {
  sz[v] = 1;
  dep[v] = dep[p] + 1;
  vert[ptr] = v;
  st[v] = ptr++;
  for (auto x : g[v]) {
    if (x.first == p) continue;
    int u = x.first;
    mask[u] = mask[v] ^ (1 << (x.second - 'a'));
    dfs(u, v);
    sz[v] += sz[u];
  }
  en[v] = ptr;
}
inline int get(int msk) {
  int ret = -1;
  if (~mp[msk]) ret = max(ret, mp[msk]);
  for (int i = 0; i < 22; i++) {
    if (~mp[msk ^ (1 << i)]) ret = max(ret, mp[msk ^ (1 << i)]);
  }
  return ret;
}
void dsu(int v, int p, bool flg) {
  int bg = -1;
  for (auto x : g[v]) {
    if (x.first != p && (bg == -1 || sz[bg] < sz[x.first])) bg = x.first;
  }
  for (auto x : g[v]) {
    if (x.first != p && x.first != bg) dsu(x.first, v, false);
  }
  if (~bg) dsu(bg, v, true);
  mp[mask[v]] = max(mp[mask[v]], dep[v]);
  ans[v] = get(mask[v]) - dep[v];
  for (auto x : g[v]) {
    int u = x.first;
    if (u == p || u == bg) continue;
    for (int i = st[u]; i < en[u]; i++) {
      int w = vert[i];
      int tmp = get(mask[w]);
      if (tmp != -1) ans[v] = max(ans[v], tmp + dep[w] - 2 * dep[v]);
    }
    for (int i = st[u]; i < en[u]; i++) {
      int w = vert[i];
      mp[mask[w]] = max(mp[mask[w]], dep[w]);
    }
  }
  if (!flg) {
    mp[mask[v]] = -1;
    for (auto x : g[v]) {
      int u = x.first;
      if (u == p) continue;
      for (int i = st[u]; i < en[u]; i++) {
        int w = vert[i];
        mp[mask[w]] = -1;
      }
    }
  }
}
void ddfs(int v, int p) {
  for (auto x : g[v]) {
    if (x.first != p) {
      ddfs(x.first, v);
      ans[v] = max(ans[v], ans[x.first]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(32);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int u;
    char ch;
    cin >> u >> ch;
    g[u].push_back({i, ch});
  }
  ptr = 1;
  dep[0] = 0;
  mask[0] = mask[1] = 0;
  dfs(1, 0);
  memset(mp, -1, sizeof(mp));
  dsu(1, 0, false);
  ddfs(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
