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 = 500005;
const int DEAD = -0xdeadbee;
int n, ans[N];
vector<int> adj[N];
char data[N];
int mask[N], dmask[N], dp[N], heavy[N], w[N], dep[N];
void dfsHeavy(int u, int p = -1) {
  w[u] = 1;
  for (int v : adj[u]) {
    if (v != p) {
      dmask[v] ^= dmask[u];
      dep[v] = dep[u] + 1;
      dfsHeavy(v, u);
      w[u] += w[v];
      if (w[heavy[u]] < w[v]) heavy[u] = v;
    }
  }
}
const int letters = 'v' - 'a' + 1;
vector<int> len[1 << 22];
int get(int mask) { return len[mask].empty() ? DEAD : len[mask].back(); }
void push(int mask, int dep) {
  vector<int>& vec = len[mask];
  int top = vec.empty() ? DEAD : vec.back();
  vec.push_back(max(top, dep));
}
void count_down(int u, int p, int lca, int& res) {
  int d = dmask[u];
  res = max(res, dep[u] + get(d) - 2 * lca);
  for (int k = 0; k < 22; ++k)
    res = max(res, get(d ^ (1 << k)) + dep[u] - 2 * lca);
  for (int v : adj[u])
    if (v != p) count_down(v, u, lca, res);
}
void add_down(int u, int p) {
  push(dmask[u], dep[u]);
  for (int v : adj[u])
    if (v != p) add_down(v, u);
}
void clear_down(int u, int p) {
  vector<int>& vec = len[dmask[u]];
  vec.pop_back();
  for (int v : adj[u])
    if (v != p) clear_down(v, u);
}
int dfs(int u, int p = -1, bool keep = true) {
  int res = 0;
  for (int v : adj[u])
    if (v != p && v != heavy[u]) res = max(res, dfs(v, u, false));
  if (heavy[u]) res = max(res, dfs(heavy[u], u, true));
  res = max(res, get(dmask[u]) - dep[u]);
  for (int k = 0; k < 22; ++k)
    res = max(res, get(dmask[u] ^ (1 << k)) - dep[u]);
  push(dmask[u], dep[u]);
  for (int v : adj[u])
    if (v != p && v != heavy[u]) {
      count_down(v, u, dep[u], res);
      add_down(v, u);
    }
  if (!keep) {
    clear_down(u, p);
  }
  dp[u] = res;
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int u;
    scanf("%d %c", &u, &data[i]);
    adj[u].push_back(i);
    dmask[i] = mask[i] = (1 << (data[i] - 'a'));
  }
  dfsHeavy(1);
  dfs(1);
  for (int i = 1; i <= n; ++i) {
    if (i != 1) printf(" ");
    printf("%d", dp[i]);
  }
  printf("\n");
}
