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;
template <typename T>
inline void next_int(T &x) {
  x = 0;
  char c;
  bool neg = false;
  while (!isdigit(c = getchar()))
    if (c == '-') neg = true;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
  if (neg) x = -x;
}
template <typename T>
inline void write_int(T x, char last = 0) {
  if (x < 0) putchar('-'), x = abs(x);
  char tmp[20];
  int cnt = 0;
  while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;
  tmp[cnt] = x + 48;
  for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);
  if (last) putchar(last);
}
const int N = (int)5e5 + 5;
int n, m, dp[N], dep[N], sz[N], tin[N], tout[N], a[N];
int heavy[N], maxd[1 << 22], mask[N], timer;
vector<vector<pair<int, int> > > g;
void dfs_prep(int u, int p) {
  sz[u] = 1, dep[u] = dep[p] + 1, tin[u] = ++timer, a[timer] = u;
  for (int i = (0); i < (((int)g[u].size())); ++i) {
    int v = g[u][i].first, c = g[u][i].second;
    if (v == p) continue;
    mask[v] = mask[u] ^ (1 << c);
    dfs_prep(v, u);
    sz[u] += sz[v];
    if (!heavy[u] || sz[heavy[u]] < sz[v]) heavy[u] = v;
  }
  tout[u] = timer;
}
void dfs_calc(int u, int p, bool keep) {
  for (int i = (0); i < (((int)g[u].size())); ++i) {
    int v = g[u][i].first;
    if (v == p || v == heavy[u]) continue;
    dfs_calc(v, u, 0);
    dp[u] = max(dp[u], dp[v]);
  }
  if (heavy[u]) {
    dfs_calc(heavy[u], u, 1);
    dp[u] = max(dp[u], dp[heavy[u]]);
  }
  for (int i = (0); i < (((int)g[u].size())); ++i) {
    int v = g[u][i].first;
    if (v == p || v == heavy[u]) continue;
    for (int it = tin[v]; it <= tout[v]; ++it) {
      int k = a[it];
      dp[u] = max(dp[u], dep[k] + maxd[mask[k]] - 2 * dep[u]);
      for (int j = (0); j < (22); ++j)
        dp[u] = max(dp[u], dep[k] + maxd[mask[k] ^ (1 << j)] - 2 * dep[u]);
    }
    for (int it = tin[v]; it <= tout[v]; ++it)
      maxd[mask[a[it]]] = max(maxd[mask[a[it]]], dep[a[it]]);
  }
  for (int j = (0); j < (22); ++j)
    dp[u] = max(dp[u], maxd[mask[u] ^ (1 << j)] - dep[u]);
  dp[u] = max(dp[u], maxd[mask[u]] - dep[u]);
  maxd[mask[u]] = max(maxd[mask[u]], dep[u]);
  if (!keep) {
    for (int it = tin[u]; it <= tout[u]; ++it)
      maxd[mask[a[it]]] = -((int)1e9 + 7);
  }
}
int main() {
  next_int(n);
  g.resize(n + 1);
  for (int i = (1); i < (n); ++i) {
    int p;
    char ch;
    next_int(p), ch = getchar();
    while (!(ch >= 'a' && ch <= 'v')) ch = getchar();
    g[p].push_back(pair<int, int>(i + 1, ch - 'a'));
    g[i + 1].push_back(pair<int, int>(p, ch - 'a'));
  }
  dfs_prep(1, 0);
  fill(maxd, maxd + (1 << 22), -((int)1e9 + 7));
  dfs_calc(1, 0, 0);
  for (int i = (1); i <= (n); ++i) write_int(dp[i], ' ');
  return 0;
}
