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 + 10, mod = 1e9 + 7;
int n, sz[N], t = 1, in[N], out[N], pref[N], ver[N], dep[N], dp[N], mx[1 << 22],
              vis[1 << 22], T;
vector<pair<int, int>> adj[N];
void pre(int u, int pa, int mask) {
  sz[u] = 1;
  in[u] = t;
  pref[u] = mask;
  dep[u] = dep[pa] + 1;
  ver[t++] = u;
  for (auto x : adj[u]) {
    int v = x.first, c = x.second;
    if (v == pa) continue;
    pre(v, u, (mask ^ (1 << c)));
    sz[u] += sz[v];
  }
  out[u] = t;
}
void dfs(int u, int pa) {
  T++;
  int big = -1, child = -1;
  for (auto x : adj[u]) {
    int v = x.first;
    if (v == pa) continue;
    if (sz[v] > big) {
      big = sz[v];
      child = v;
    }
  }
  for (auto x : adj[u]) {
    int v = x.first;
    if (v == pa || v == child) continue;
    dfs(v, u);
    dp[u] = max(dp[u], dp[v]);
  }
  int cur = T;
  if (child != -1) dfs(child, u), dp[u] = max(dp[u], dp[child]);
  mx[pref[u]] = max((vis[pref[u]] >= cur ? mx[pref[u]] : 0), dep[u]);
  vis[pref[u]] = T++;
  dp[u] = max(dp[u], mx[pref[u]] - dep[u]);
  for (int j = 0; j < 22; j++) {
    if (vis[(pref[u] ^ (1 << j))] >= cur)
      dp[u] = max(dp[u], mx[(pref[u] ^ (1 << j))] - dep[u]);
  }
  for (auto x : adj[u]) {
    int v = x.first;
    if (v == pa || v == child) continue;
    for (int s = in[v]; s < out[v]; s++) {
      int V = ver[s];
      if (vis[pref[V]] >= cur)
        dp[u] = max(dp[u], mx[pref[V]] + dep[V] - 2 * dep[u]);
      if (__builtin_popcount((pref[V] ^ pref[u])) < 2)
        dp[u] = max(dp[u], dep[V] - dep[u]);
      for (int j = 0; j < 22; j++) {
        if (vis[((1 << j) ^ pref[V])] >= cur)
          dp[u] = max(dp[u], mx[((1 << j) ^ pref[V])] + dep[V] - 2 * dep[u]);
      }
    }
    for (int s = in[v]; s < out[v]; s++) {
      int V = ver[s];
      mx[pref[V]] = max((vis[pref[V]] >= cur ? mx[pref[V]] : 0), dep[V]);
      vis[pref[V]] = T++;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    getchar();
    char ch = getchar();
    adj[i].push_back({p, ch - 'a'});
    adj[p].push_back({i, ch - 'a'});
  }
  pre(1, 1, 0);
  dfs(1, 1);
  for (int i = 1; i <= n; i++) printf("%d ", dp[i]);
  return 0;
}
