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;
clock_t __START, __END;
double __TOTALTIME;
void _MS() { __START = clock(); }
void _ME() {
  __END = clock();
  __TOTALTIME = (double)(__END - __START) / CLOCKS_PER_SEC;
  cout << "Time: " << __TOTALTIME << " s" << endl;
}
const double E = 2.718281828;
const double PI = acos(-1.0);
const long long INF = (1LL << 60);
const int inf = (1 << 30);
const double ESP = 1e-9;
const int mod = (int)1e9 + 7;
const int N = (int)1e6 + 10;
struct EDGE {
  int to, next;
  int c;
} edge[N << 1];
int tot;
int head[N];
void add(int from, int to, int c) {
  ++tot;
  edge[tot].to = to;
  edge[tot].c = c;
  edge[tot].next = head[from];
  head[from] = tot;
}
int sz[N], Bigson[N], vb[N], dis[N], deep[N];
char s[N];
int ans[N];
void dfs(int x, int fa, int dep, int val) {
  sz[x] = 1;
  dis[x] = val;
  deep[x] = dep;
  for (int i = head[x]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to == fa) continue;
    dfs(to, x, dep + 1, val ^ edge[i].c);
    sz[x] += sz[to];
    if (sz[Bigson[x]] < sz[to]) Bigson[x] = to, vb[x] = edge[i].c;
  }
}
int Son;
bool okself(int xx) {
  bool ok = 0;
  if (xx == 0) ok = 1;
  for (int i = 1; i <= 22; ++i)
    if ((xx ^ (1 << (i - 1))) == 0) ok = 1;
  return ok;
}
int mark[1 << 23];
void goself(int x, int fa, int who) {
  mark[dis[x]] = max(mark[dis[x]], deep[x]);
  if (okself(dis[x] ^ dis[who])) ans[who] = max(ans[who], deep[x] - deep[who]);
  for (int i = head[x]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to == fa || to == Son) continue;
    goself(to, x, who);
  }
}
void go(int x, int fa, int who) {
  if (mark[dis[x]])
    ans[who] = max(ans[who], mark[dis[x]] + deep[x] - 2 * deep[who]);
  for (int i = 1; i <= 22; ++i)
    if (mark[dis[x] ^ (1 << (i - 1))])
      ans[who] = max(ans[who],
                     mark[dis[x] ^ (1 << (i - 1))] + deep[x] - 2 * deep[who]);
  for (int i = head[x]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to == fa || to == Son) continue;
    go(to, x, who);
  }
}
void del(int x, int fa) {
  mark[dis[x]] = 0;
  for (int i = head[x]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to == fa) continue;
    del(to, x);
  }
}
void dfs2(int x, int fa, int op) {
  for (int i = head[x]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to == fa) continue;
    if (to != Bigson[x]) dfs2(to, x, 0), ans[x] = max(ans[x], ans[to]);
  }
  if (Bigson[x]) dfs2(Bigson[x], x, 1), ans[x] = max(ans[x], ans[Bigson[x]]);
  Son = Bigson[x];
  if (mark[dis[x]]) ans[x] = max(ans[x], mark[dis[x]] - deep[x]);
  for (int i = 1; i <= 22; ++i)
    if (mark[dis[x] ^ (1 << (i - 1))])
      ans[x] = max(ans[x], mark[dis[x] ^ (1 << (i - 1))] - deep[x]);
  mark[dis[x]] = max(mark[dis[x]], deep[x]);
  for (int i = head[x]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to == fa) continue;
    if (to != Bigson[x]) go(to, x, x), goself(to, x, x);
  }
  if (!op) del(x, fa);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    char temp[5];
    int u;
    scanf("%d%s", &u, temp);
    add(u, i, 1 << (temp[0] - 'a'));
    add(i, u, 1 << (temp[0] - 'a'));
  }
  dfs(1, -1, 1, 0);
  dfs2(1, -1, 1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
