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, mx[500200], p[500200], ind[500200], ans[500200], f[500200], d[500200];
vector<pair<int, int> > g[500200];
unordered_map<int, int> mp[500200];
char c[500200];
void Merge(int a, int b, int vert) {
  unordered_map<int, int>::iterator it = mp[a].begin();
  while (it != mp[a].end()) {
    int x = (it->first) ^ f[a] ^ f[b];
    for (int i = 0; i < 23; i++) {
      if (it->second + mx[vert] - d[vert] <= ans[vert]) continue;
      if (i != 22 && mp[b].count(x ^ (1 << i)))
        ans[vert] =
            max(ans[vert], it->second + mp[b][x ^ (1 << i)] - 2 * d[vert]);
      if (i == 22 && mp[b].count(x))
        ans[vert] = max(ans[vert], it->second + mp[b][x] - 2 * d[vert]);
    }
    ++it;
  }
  it = mp[a].begin();
  while (it != mp[a].end()) {
    int x = it->first ^ f[a] ^ f[b];
    if (!mp[b].count(x))
      mp[b][x] = it->second;
    else
      mp[b][x] = max(mp[b][x], it->second);
    ++it;
  }
  mp[a].clear();
}
void dfs(int v) {
  int i;
  ind[v] = v;
  mx[v] = d[v];
  mp[ind[v]][0] = d[v];
  for (i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    d[to] = d[v] + 1;
    dfs(to);
    mx[v] = max(mx[v], mx[to]);
    ans[v] = max(ans[v], ans[to]);
    f[ind[to]] ^= g[v][i].second;
    if (mp[ind[to]].size() < mp[ind[v]].size()) {
      Merge(ind[to], ind[v], v);
    } else {
      Merge(ind[v], ind[to], v);
      ind[v] = ind[to];
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%s", &p[i], &c[i]);
    g[--p[i]].push_back({i, 1 << (c[i] - 'a')});
  }
  dfs(0);
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
  return 0;
}
