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;
inline void chkmax(int &x, int y) { x < y ? (x = y) : 0; }
const int N = 500005;
vector<pair<int, int> > G[N];
int size[N], in[N], out[N], id[N], dep[N], son[N], tot;
int Xor[N], f[1 << 22], ans[N];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return x * f;
}
void dfs(int u) {
  size[u] = 1;
  id[in[u] = ++tot] = u;
  for (auto i : G[u]) {
    dep[i.first] = dep[u] + 1;
    Xor[i.first] = Xor[u] ^ i.second;
    dfs(i.first);
    size[u] += size[i.first];
    if (size[i.first] > size[son[u]]) son[u] = i.first;
  }
  out[u] = tot;
}
void solve(int u, int flag) {
  for (auto i : G[u])
    if (i.first ^ son[u]) solve(i.first, 0), chkmax(ans[u], ans[i.first]);
  if (son[u]) solve(son[u], 1), chkmax(ans[u], ans[son[u]]);
  if (f[Xor[u]]) chkmax(ans[u], f[Xor[u]] - dep[u]);
  for (register int i = (0); i <= (21); ++i)
    if (f[Xor[u] ^ (1 << i)]) chkmax(ans[u], f[Xor[u] ^ (1 << i)] - dep[u]);
  chkmax(f[Xor[u]], dep[u]);
  for (auto i : G[u])
    if (i.first ^ son[u]) {
      for (register int j = (in[i.first]); j <= (out[i.first]); ++j) {
        if (f[Xor[id[j]]])
          chkmax(ans[u], f[Xor[id[j]]] + dep[id[j]] - (dep[u] << 1));
        for (register int k = (0); k <= (21); ++k)
          if (f[Xor[id[j]] ^ (1 << k)])
            chkmax(ans[u],
                   f[Xor[id[j]] ^ (1 << k)] + dep[id[j]] - (dep[u] << 1));
      }
      for (register int j = (in[i.first]); j <= (out[i.first]); ++j)
        chkmax(f[Xor[id[j]]], dep[id[j]]);
    }
  if (!flag)
    for (register int i = (in[u]); i <= (out[u]); ++i) f[Xor[id[i]]] = 0;
}
int main() {
  int n = read();
  for (register int i = (2); i <= (n); ++i) {
    int p = read();
    char c = getchar();
    G[p].push_back(make_pair(i, 1 << (c - 'a')));
  }
  dep[1] = 1;
  dfs(1);
  solve(1, 0);
  for (register int i = (1); i <= ((1 << 22) - 1); ++i)
    if (f[i]) printf("%d %d\n", i, f[i]);
  for (register int i = (1); i <= (n); ++i) printf("%d ", ans[i]);
  return 0;
}
