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;
int n;
vector<pair<int, int> > a[500020];
int b[500020], c[500020], h[500020], bit[500020], answer[500020];
int big[500020], sz[500020];
vector<int> G[500020];
void dfs(int v) {
  big[v] = 0;
  for (int i = 0; i < G[v].size(); ++i) {
    int to = G[v][i];
    bit[to] = (bit[v] ^ (1 << c[to]));
    h[to] = h[v] + 1;
    dfs(to);
    sz[v] += sz[to];
    if (sz[to] > sz[big[v]]) big[v] = to;
  }
  sz[v]++;
}
int ans[4194310];
void go(int v, bool op) {
  for (int i = 0; i < G[v].size(); ++i) {
    int to = G[v][i];
    if (to == big[v]) continue;
    go(to, 0);
  }
  b[v] = v;
  if (big[v]) go(big[v], 1), b[v] = b[big[v]];
  for (int k = 0; k < 22; ++k)
    answer[v] = max(answer[v], ans[((1 << k) ^ bit[v])] - h[v]);
  answer[v] = max(answer[v], ans[bit[v]] - h[v]);
  a[b[v]].push_back(make_pair(bit[v], h[v]));
  ans[bit[v]] = max(ans[bit[v]], h[v]);
  for (int i = 0; i < G[v].size(); ++i) {
    int to = G[v][i];
    if (to == big[v]) continue;
    for (int j = 0; j < a[b[to]].size(); ++j) {
      for (int k = 0; k < 22; ++k)
        answer[v] = max(answer[v], ans[((1 << k) ^ a[b[to]][j].first)] +
                                       a[b[to]][j].second - 2 * h[v]);
      answer[v] = max(answer[v],
                      ans[a[b[to]][j].first] + a[b[to]][j].second - 2 * h[v]);
    }
    for (int j = 0; j < a[b[to]].size(); ++j) {
      ans[a[b[to]][j].first] = max(ans[a[b[to]][j].first], a[b[to]][j].second);
      a[b[v]].push_back(a[b[to]][j]);
    }
    a[b[to]].clear();
  }
  for (int i = 0; i < G[v].size(); ++i)
    answer[v] = max(answer[v], answer[G[v][i]]);
  if (op) return;
  for (int i = 0; i < a[b[v]].size(); ++i) ans[a[b[v]][i].first] = -1e9;
  ans[0] = 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (1 << 22); ++i) ans[i] = -1e9;
  for (int i = 2; i <= n; ++i) {
    int x;
    char ch;
    scanf("%d", &x);
    ch = getchar();
    while (ch < 'a' || ch > 'z') ch = getchar();
    c[i] = ch - 'a';
    G[x].push_back(i);
  }
  dfs(1);
  go(1, 1);
  for (int i = 1; i <= n; ++i) printf("%d ", answer[i]);
}
