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;
void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }
const int inf = 0x3f3fffff;
const int N = 5e5 + 1e4;
struct E {
  int v, next;
  char c;
} edge[N];
int head[N], depth[N], sz[N], son[N];
int ans[N], mp[(1 << 22) + 1000], path[N], L[N], R[N], dfs2idx[N];
int n, edge_cnt, dfn;
void add_edge(int u, int v, char c) {
  edge[edge_cnt] = {v, head[u], c};
  head[u] = edge_cnt++;
}
void pre_dfs(int u) {
  sz[u] = 1;
  L[u] = ++dfn;
  dfs2idx[dfn] = u;
  for (int e = head[u], v; ~e; e = edge[e].next) {
    v = edge[e].v;
    depth[v] = depth[u] + 1;
    path[v] = path[u] ^ (1 << (edge[e].c - 'a'));
    pre_dfs(v);
    sz[u] += sz[v];
    if (son[u] == -1 || sz[v] > sz[son[u]]) son[u] = v;
  }
  R[u] = dfn;
}
void dfs(int u, bool keep) {
  for (int e = head[u], v; ~e; e = edge[e].next) {
    v = edge[e].v;
    if (v != son[u]) dfs(v, false), ans[u] = max(ans[u], ans[v]);
  }
  if (son[u] != -1) {
    dfs(son[u], true);
    ans[u] = max(ans[u], ans[son[u]]);
    int mask = path[u];
    ans[u] = max(ans[u], mp[mask] - depth[u]);
    for (int j = 0; j < 22; j++)
      ans[u] = max(ans[u], mp[(mask) ^ (1 << j)] - depth[u]);
  }
  mp[path[u]] = max(mp[path[u]], depth[u]);
  for (int e = head[u], v; ~e; e = edge[e].next) {
    v = edge[e].v;
    if (v == son[u]) continue;
    for (int i = L[v]; i <= R[v]; i++) {
      int p = dfs2idx[i], mask = path[p];
      ans[u] = max(ans[u], mp[mask] + depth[p] - 2 * depth[u]);
      for (int j = 0; j < 22; j++) {
        ans[u] = max(ans[u], mp[(mask) ^ (1 << j)] + depth[p] - 2 * depth[u]);
      }
    }
    for (int i = L[v]; i <= R[v]; i++)
      mp[path[dfs2idx[i]]] = max(mp[path[dfs2idx[i]]], depth[dfs2idx[i]]);
  }
  if (!keep) {
    for (int i = L[u]; i <= R[u]; i++) mp[path[dfs2idx[i]]] = -inf;
  }
}
void solve() {
  edge_cnt = dfn = 0;
  cin >> n;
  fill(begin(mp), end(mp), -inf);
  memset(son, -1, sizeof son);
  for (int i = 0; i <= n; i++) head[i] = -1, ans[i] = 0;
  for (int i = 1, v; i < n; i++) {
    char c;
    cin >> v >> c;
    add_edge(v, i + 1, c);
  }
  depth[1] = 1, path[1] = 0;
  pre_dfs(1);
  dfs(1, 1);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
}
signed main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  solve();
}
