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<pair<int, int> > G[500005];
int sz[500005];
vector<int> *vec[500005];
int cnt[(1 << 23) + 5];
int lazy[500005];
int len[500005];
int res[500005];
void get_ready(int u, int par, int mask, int hh) {
  sz[u] = 1;
  len[u] = hh;
  lazy[u] = mask;
  for (auto v : G[u])
    if (v.first != par)
      get_ready(v.first, u, mask ^ v.second, hh + 1), sz[u] += sz[v.first];
}
void DFS(int u, int par, int keep, int mask) {
  int node = -1, mx = 0, xr = 0;
  for (auto x : G[u]) {
    int v = x.first;
    if (par != v and sz[v] > mx) {
      mx = sz[v], node = v, xr = x.second;
    }
  }
  for (auto x : G[u]) {
    int v = x.first;
    if (v != par and v != node) DFS(v, u, 0, x.second);
  }
  if (node != -1) {
    DFS(node, u, 1, xr);
    vec[u] = vec[node];
    res[u] = max(res[u], res[node]);
  } else
    vec[u] = new vector<int>;
  for (int i = 1; i <= (1 << 22); i <<= 1) {
    res[u] = max(res[u], cnt[lazy[u] ^ i] - len[u]);
  }
  res[u] = max(res[u], cnt[lazy[u]] - len[u]);
  cnt[lazy[u]] = max(cnt[lazy[u]], len[u]);
  vec[u]->push_back(u);
  for (auto x : G[u]) {
    int v = x.first;
    if (v != par and v != node) {
      res[u] = max(res[u], res[v]);
      for (auto vv : *vec[v]) {
        for (int i = 1; i <= (1 << 22); i <<= 1) {
          res[u] = max(res[u], len[vv] + cnt[lazy[vv] ^ i] - 2 * len[u]);
        }
        res[u] = max(res[u], len[vv] + cnt[lazy[vv]] - 2 * len[u]);
      }
      for (auto vv : *vec[v]) {
        int temp = lazy[vv];
        cnt[temp] = max(cnt[temp], len[vv]);
        vec[u]->push_back(vv);
      }
      vec[v]->clear();
    }
  }
  if (!keep) {
    for (auto v : *vec[u]) cnt[lazy[v]] = -1000000000;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 0; i < (1 << 23) + 5; i++) cnt[i] = -1000000000;
  int N;
  cin >> N;
  for (int i = 2; i <= N; i++) {
    string ch;
    int p;
    cin >> p >> ch;
    G[p].push_back({i, 1 << (ch[0] - 'a')});
    G[i].push_back({p, 1 << (ch[0] - 'a')});
  }
  get_ready(1, -1, 0, 0);
  DFS(1, -1, 1, 0);
  for (int i = 1; i <= N; i++) cout << res[i] << " ";
}
