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 + 5;
const int A = 22;
using ll = long long;
using ii = pair<int, int>;
const int oo = 0x3f3f3f3f;
int my_rank[2 << A];
int dep[N];
stack<ii> changes;
int answer[N];
vector<ii> g[N];
int sz[N];
int down[N];
void build(int u, int c = 0, int p = 0) {
  dep[u] = dep[p] + 1;
  if (p > 0) down[u] = down[p] ^ (1 << c);
  sz[u] = 1;
  for (auto& e : g[u]) {
    build(e.first, e.second, u);
    sz[u] += sz[e.first];
    if (sz[e.first] > sz[g[u][0].first]) {
      swap(e, g[u][0]);
    }
  }
}
void insert(int u) {
  int x = down[u];
  changes.emplace(x, my_rank[x]);
  my_rank[x] = max(my_rank[x], dep[u]);
}
int all_matches(int u, int lca_dep) {
  int ans = my_rank[down[u]] + dep[u] - 2 * lca_dep;
  for (int c = 0; c < A; c++)
    ans = max(ans, my_rank[down[u] ^ (1 << c)] + dep[u] - 2 * lca_dep);
  return ans;
}
int add_matches(int u, int lca_dep) {
  int ans = all_matches(u, lca_dep);
  for (auto [v, _] : g[u]) ans = max(ans, add_matches(v, lca_dep));
  return ans;
}
void add_subtree(int u) {
  insert(u);
  for (auto [v, c] : g[u]) add_subtree(v);
}
void remove_subtree(int u) {
  for (int i = 0; i < sz[u]; i++) {
    auto [x, bef] = changes.top();
    changes.pop();
    my_rank[x] = bef;
  }
}
void dfs(int u, bool keep = false) {
  if (g[u].size() == 0) {
    if (keep) insert(u);
    return;
  }
  for (int i = 1; i < (int)g[u].size(); i++) {
    dfs(g[u][i].first);
  }
  dfs(g[u][0].first, true);
  for (int i = 1; i < (int)g[u].size(); i++) {
    answer[u] = max(answer[u], add_matches(g[u][i].first, dep[u]));
    add_subtree(g[u][i].first);
  }
  answer[u] = max(answer[u], all_matches(u, dep[u]));
  insert(u);
  if (!keep) {
    remove_subtree(u);
  }
}
void get_max(int u) {
  for (auto [v, _] : g[u]) {
    get_max(v);
    answer[u] = max(answer[u], answer[v]);
  }
}
int(((((((main)))))))() {
  cin.tie(0)->sync_with_stdio(false);
  memset(my_rank, -oo, sizeof(my_rank));
  int n;
  cin >> n;
  for (int u = 2; u <= n; u++) {
    int p;
    char c;
    cin >> p >> c;
    g[p].emplace_back(u, c - 'a');
  }
  build(1);
  dfs(1);
  get_max(1);
  for (int u = 1; u <= n; u++) cout << answer[u] << ' ';
  cout << '\n';
  return 0;
}
