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 long long int inf = 1e9;
const long long int N = 500005;
long long int val[N], lol[N], ans[N], depth[N], sz[N];
long long int s[1 << 22];
long long int euler[N], st[N], e[N];
vector<pair<long long int, long long int>> g[N];
long long int h[23];
long long int tt;
void dfs(long long int u, long long int p, long long int c) {
  st[u] = ++tt;
  euler[tt] = u;
  val[u] = c;
  sz[u] = 1;
  for (auto v : g[u]) {
    if (v.first != p) {
      depth[v.first] = depth[u] + 1;
      dfs(v.first, u, (v.second ^ val[u]));
      sz[u] += sz[v.first];
    }
  }
  e[u] = tt;
}
void dfs1(long long int u, long long int p, bool ret) {
  long long int h_child = -1, S = 0;
  for (auto v : g[u]) {
    if (v.first != p) {
      if (sz[v.first] > S) {
        S = sz[v.first], h_child = v.first;
      }
    }
  }
  if (h_child == -1) {
    if (ret) s[val[u]] = max(s[val[u]], depth[u]);
    return;
  }
  for (auto v : g[u]) {
    if (v.first != p && v.first != h_child) {
      dfs1(v.first, u, 0);
      ans[u] = max(ans[u], ans[v.first]);
    }
  }
  dfs1(h_child, u, 1);
  ans[u] = max(ans[u], ans[h_child]);
  for (auto v : g[u]) {
    if (v.first != p && v.first != h_child) {
      for (long long int i = st[v.first]; i <= e[v.first]; i++) {
        for (long long int j = 0; j < 23; j++) {
          long long int hh = (h[j] ^ val[euler[i]]);
          ans[u] = max(ans[u], depth[euler[i]] + s[hh] - 2 * depth[u]);
        }
      }
      for (long long int i = st[v.first]; i <= e[v.first]; i++) {
        s[val[euler[i]]] = max(s[val[euler[i]]], depth[euler[i]]);
      }
    }
  }
  s[val[u]] = max(s[val[u]], depth[u]);
  for (long long int j = 0; j < 23; j++) {
    long long int hh = (h[j] ^ val[u]);
    ans[u] = max(ans[u], s[hh] - depth[u]);
  }
  if (!ret) {
    for (long long int i = st[u]; i <= e[u]; i++) {
      s[val[euler[i]]] = -inf;
    }
  }
}
signed main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (long long int i = 1; i <= 22; i++) {
    h[i] = 1 << (i - 1);
  }
  for (long long int i = 0; i <= (1 << 22) - 1; i++) s[i] = -inf;
  long long int n;
  cin >> n;
  for (long long int i = 2; i <= n; i++) {
    long long int p;
    char ch;
    cin >> p >> ch;
    g[p].push_back({i, 1 << (ch - 'a')});
    g[i].push_back({p, 1 << (ch - 'a')});
  }
  dfs(1, 0, 0);
  dfs1(1, 0, 1);
  for (long long int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
