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 + 7, mod = 1e9 + 7, inf = 1e5 + 7;
const long long linf = (long long)1e18 + 7;
const long double eps = 1e-15, pi = 3.141592;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1},
          dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
inline int get_int() {
  char x = getchar();
  while (!('0' <= x && x <= '9')) x = getchar();
  int res = 0;
  while ('0' <= x && x <= '9') res = res * 10 + x - '0', x = getchar();
  return res;
}
inline void put_int(int x) {
  if (x > 9) put_int(x / 10);
  putchar(x % 10 + '0');
}
int n;
int a[N], sz[N], lvl[N], ans[N], h[1 << 22];
vector<pair<int, int> > g[N];
inline void calc(int v = 1, int p = 1, int mask = 0) {
  sz[v] = 1, a[v] = mask, lvl[v] = lvl[p] + 1;
  for (auto i : g[v])
    calc(i.first, v, mask ^ (1 << i.second)), sz[v] += sz[i.first];
}
inline void go(int v, int p) {
  for (auto i : g[v]) go(i.first, p);
  ans[p] = max(ans[p], lvl[v] + h[a[v]] - lvl[p] * 2);
  for (int i = 0; i <= 21; ++i)
    ans[p] = max(ans[p], lvl[v] + h[a[v] ^ (1 << i)] - lvl[p] * 2);
}
inline void add(int v) {
  h[a[v]] = max(h[a[v]], lvl[v]);
  for (auto i : g[v]) add(i.first);
}
inline void del(int v) {
  h[a[v]] = -inf;
  for (auto i : g[v]) del(i.first);
}
inline void dfs(int v = 1, bool keep = 0) {
  int mx = -1, id = -1;
  for (auto i : g[v])
    if (sz[i.first] > mx) mx = sz[i.first], id = i.first;
  for (auto i : g[v])
    if (i.first != id) dfs(i.first, 0), ans[v] = max(ans[v], ans[i.first]);
  if (id != -1) dfs(id, 1), ans[v] = max(ans[v], ans[id]);
  for (auto i : g[v])
    if (i.first != id) go(i.first, v), add(i.first);
  h[a[v]] = max(h[a[v]], lvl[v]);
  for (int i = 0; i <= 21; ++i)
    ans[v] = max(ans[v], h[a[v] ^ (1 << i)] - lvl[v]);
  ans[v] = max(ans[v], h[a[v]] - lvl[v]);
  if (!keep) del(v);
}
int main() {
  n = get_int();
  int x;
  char c;
  for (int i = 2; i <= n; ++i) {
    x = get_int();
    c = getchar();
    g[x].push_back({i, c - 'a'});
  }
  for (int i = 0; i <= (1 << 22) - 1; ++i) h[i] = -inf;
  calc(), dfs();
  for (int i = 1; i <= n; ++i) put_int(ans[i]), putchar(' ');
  exit(0);
}
