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;
vector<int> xors(23);
vector<pair<int, int> > vec[500005];
int sz[500005];
int path[500005];
int level[500005];
int mx[1 << 23];
int ans[500005];
vector<int> *sub[500005];
void setup(int s, int ald, int lev) {
  sz[s] = 1;
  path[s] = ald, level[s] = lev;
  for (pair<int, int> nxt : vec[s]) {
    int v = nxt.first;
    setup(v, ald ^ (1 << nxt.second), lev + 1);
    sz[s] += sz[v];
  }
}
void dfs(int s, bool keep) {
  int msz = -1, big = -1;
  for (pair<int, int> nxt : vec[s]) {
    int v = nxt.first;
    if (sz[v] > msz) msz = sz[v], big = v;
  }
  for (pair<int, int> nxt : vec[s]) {
    int v = nxt.first;
    if (v != big) dfs(v, false), ans[s] = max(ans[s], ans[v]);
  }
  if (big != -1) {
    dfs(big, true);
    ans[s] = max(ans[s], ans[big]);
    sub[s] = sub[big];
  } else
    sub[s] = new vector<int>();
  for (int x : xors) ans[s] = max(ans[s], mx[path[s] ^ x] - level[s]);
  mx[path[s]] = max(mx[path[s]], level[s]);
  sub[s]->push_back(s);
  for (pair<int, int> nxt : vec[s]) {
    int v = nxt.first;
    if (v == big) continue;
    for (int p : *sub[v]) {
      for (int x : xors)
        ans[s] = max(ans[s], mx[path[p] ^ x] + level[p] - 2 * level[s]);
    }
    for (int p : *sub[v]) {
      mx[path[p]] = max(mx[path[p]], level[p]);
      sub[s]->push_back(p);
    }
  }
  if (!keep) {
    for (int p : *sub[s]) mx[path[p]] = -1000000000;
  }
}
int main() {
  for (int i = 1; i < 23; i++) xors[i] = 1 << (i - 1);
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    char c;
    scanf("%d %c", &p, &c);
    vec[p].push_back({i, c - 'a'});
  }
  setup(1, 0, 0);
  for (int i = 0; i < (1 << 23); i++) mx[i] = -1000000000;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
