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 inf = 1LL << 61;
const long long mod = 1000000007;
const int max_n = 500010;
const int max_ch = 22;
struct eg {
  int node;
  char ch;
};
int tsp = 0;
vector<eg> g[max_n];
int sz[max_n], dfn[max_n], dep[max_n], d[max_n];
int seq[max_n], ans[max_n], h[(1 << 22)];
void dfs(int v, int fa);
void dfs(int v, int fa, int keep);
void update(int v, int root);
void add(int v);
void remove_(int v, int fa);
int main() {
  int i = 0, j = 0, k = 0;
  int n, p;
  char ch;
  eg tmp_eg;
  memset(h, -0x3f, sizeof(h));
  memset(sz, 0, sizeof(sz)), memset(dfn, 0, sizeof(dfn));
  memset(seq, 0, sizeof(seq)), memset(ans, 0, sizeof(ans));
  memset(dep, 0, sizeof(dep)), memset(d, 0, sizeof(d));
  scanf("%d", &n);
  for (i = 2; i <= n; i++) {
    scanf("%d %c", &p, &ch);
    tmp_eg.node = i;
    tmp_eg.ch = ch;
    g[p].push_back(tmp_eg);
    tmp_eg.node = p;
    g[i].push_back(tmp_eg);
  }
  dfs(1, 0);
  dfs(1, 0, 1);
  for (i = 1; i <= n; i++) {
    printf("%d%c", ans[i], i == n ? '\n' : ' ');
  }
  return 0;
}
void dfs(int v, int fa) {
  dep[v] = dep[fa] + 1;
  sz[v] = 1, dfn[v] = ++tsp, seq[tsp] = v;
  for (auto u : g[v]) {
    if (u.node != fa) {
      int i = u.ch - 'a';
      d[u.node] = d[v] ^ (1 << i);
      dfs(u.node, v);
      sz[v] += sz[u.node];
    }
  }
}
void dfs(int v, int fa, int keep) {
  int mx = 0, big_child = -1;
  for (auto u : g[v]) {
    if (u.node != fa && sz[u.node] > mx) {
      mx = sz[u.node];
      big_child = u.node;
    }
  }
  for (auto u : g[v]) {
    if (u.node != fa && u.node != big_child) {
      dfs(u.node, v, 0);
    }
  }
  if (big_child != -1) {
    dfs(big_child, v, 1);
    ans[v] = ans[big_child];
  }
  int i;
  for (auto u : g[v]) {
    if (u.node != fa && u.node != big_child) {
      ans[v] = max(ans[v], ans[u.node]);
      for (i = dfn[u.node]; i < dfn[u.node] + sz[u.node]; i++) {
        update(seq[i], v);
      }
      for (i = dfn[u.node]; i < dfn[u.node] + sz[u.node]; i++) {
        add(seq[i]);
      }
    }
  }
  update(v, v);
  add(v);
  if (keep == 0) {
    remove_(v, fa);
  }
}
void update(int v, int root) {
  ans[root] = max(ans[root], dep[v] + h[d[v]] - 2 * dep[root]);
  int i;
  for (i = 0; i < 22; i++) {
    ans[root] = max(ans[root], dep[v] + h[d[v] ^ (1 << i)] - 2 * dep[root]);
  }
}
void add(int v) { h[d[v]] = max(h[d[v]], dep[v]); }
void remove_(int v, int fa) {
  h[d[v]] = -0x3f3f3f3f;
  for (auto u : g[v]) {
    if (u.node != fa) {
      remove_(u.node, v);
    }
  }
}
