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, lg = 22, inf = 1e9 + 1;
int n, dfstime, sz[N], st[N], fn[N], num[N], px[N], mask[(1 << (lg + 1)) + 10],
    ans[N], h[N];
vector<pair<int, int> > gr[N];
void dfs(int v, int par = -1) {
  st[v] = dfstime++;
  num[st[v]] = v;
  for (auto p : gr[v]) {
    int u = p.first;
    if (p.first != par) {
      h[u] = h[v] + 1;
      px[u] = px[v] ^ (1 << p.second);
      dfs(u, v);
      sz[v] += sz[u];
    }
  }
  sz[v]++;
  fn[v] = dfstime;
}
int concat(int msk) {
  int ans1 = mask[msk];
  for (int i = 0; i <= lg; i++) {
    int rn = msk ^ (1 << i);
    ans1 = max(ans1, mask[rn]);
  }
  return ans1;
}
void getAns(int v, int par = -1, int maxi = 0) {
  int mx = 0, b = -1;
  for (auto p : gr[v]) {
    int u = p.first, e = p.second;
    if (u != par && sz[u] > mx) mx = sz[u], b = u;
  }
  for (auto p : gr[v]) {
    int u = p.first, e = p.second;
    if (u != par && b != u) {
      getAns(u, v);
      ans[v] = max(ans[v], ans[u]);
    }
  }
  if (b != -1) {
    getAns(b, v, 1);
    ans[v] = max(ans[v], ans[b]);
  }
  for (auto p : gr[v]) {
    int u = p.first;
    if (u != par && u != b) {
      for (int i = st[u]; i < fn[u]; i++) {
        ans[v] = max(ans[v], concat(px[num[i]]) + h[num[i]] - 2 * h[v]);
      }
      for (int i = st[u]; i < fn[u]; i++)
        mask[px[num[i]]] = max(h[num[i]], mask[px[num[i]]]);
    }
  }
  mask[px[v]] = max(h[v], mask[px[v]]);
  ans[v] = max(ans[v], mask[px[v]] - h[v]);
  for (int i = 0; i <= lg; i++) {
    int msk = px[v] ^ (1 << i);
    ans[v] = max(ans[v], mask[msk] - h[v]);
  }
  if (!maxi) {
    for (int i = st[v]; i < fn[v]; i++) mask[px[num[i]]] = -inf;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x;
    char c;
    cin >> x >> c;
    c -= 'a', x--;
    gr[i].push_back({x, c});
    gr[x].push_back({i, c});
  }
  dfs(0);
  fill(mask, mask + (1 << 23) + 1, -inf);
  getAns(0);
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  return 0;
}
