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 MAXC = 23;
const int MAXN = 555555 * 2;
const int INF = 1000000000;
int L[MAXN], R[MAXN], mxc[MAXN], seq[MAXN], dep[MAXN], mask[MAXN], father[MAXN],
    size[MAXN];
int f[1 << MAXC], dp[MAXN], c[MAXN], n, DFN;
vector<int> g[MAXN];
char str[11];
bool flag = true;
inline void pre_dfs(int u) {
  L[u] = ++DFN;
  seq[++DFN] = u;
  mxc[u] = -1;
  size[u] = 1;
  for (auto v : g[u]) {
    dep[v] = dep[u] + 1;
    mask[v] = mask[u] ^ (1 << c[v]);
    pre_dfs(v);
    size[u] += size[v];
    if (mxc[u] == -1 || size[v] > size[mxc[u]]) {
      mxc[u] = v;
    }
  }
  R[u] = DFN;
}
inline int update(int mask, int d) {
  int ret = -INF;
  ret = max(ret, f[mask] + d);
  for (int i = 0; i < MAXC; ++i) {
    int newmask = mask ^ (1 << i);
    ret = max(f[newmask] + d, ret);
  }
  return ret;
}
inline void dfs(int u, int keep) {
  assert(u > 0);
  for (auto v : g[u]) {
    if (v == mxc[u]) {
      continue;
    }
    dfs(v, 0);
    dp[u] = max(dp[u], dp[v]);
  }
  if (~mxc[u]) {
    dfs(mxc[u], 1);
    dp[u] = max(dp[u], dp[mxc[u]]);
  }
  for (auto v : g[u]) {
    if (v == mxc[u]) {
      continue;
    }
    for (int i = L[v]; i <= R[v]; ++i) {
      dp[u] = max(dp[u], update(mask[seq[i]], dep[seq[i]]) - dep[u] * 2);
    }
    for (int i = L[v]; i <= R[v]; ++i) {
      assert(mask[seq[i]] < 1 << MAXC);
      f[mask[seq[i]]] = max(f[mask[seq[i]]], dep[seq[i]]);
    }
  }
  assert(mask[u] < 1 << MAXC);
  f[mask[u]] = max(f[mask[u]], dep[u]);
  dp[u] = max(dp[u], update(mask[u], dep[u]) - dep[u] * 2);
  if (!keep) {
    for (int i = L[u]; i <= R[u]; ++i) {
      f[mask[seq[i]]] = -INF;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n; ++i) {
    g[i].clear();
  }
  for (int i = 2; i <= n; ++i) {
    scanf("%d %s", &father[i], str);
    if (father[i] != i / 2) {
      flag = false;
    }
    g[father[i]].push_back(i);
    c[i] = str[0] - 'a';
  }
  DFN = 0;
  mask[1] = 0;
  dep[1] = 1;
  pre_dfs(1);
  for (int i = 0; i < 1 << MAXC; ++i) {
    f[i] = -INF;
  }
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) {
    printf("%d ", dp[i]);
  }
  puts("");
}
