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 MAXN = 2e6 + 51;
struct Edge {
  int to, prev, dist;
};
Edge ed[MAXN << 1];
int nc, tot, dfn, x;
char ch;
int last[MAXN], fa[MAXN], size[MAXN], heavy[MAXN], l[MAXN], r[MAXN];
int id[MAXN], depth[MAXN], res[MAXN], vis[MAXN], barrel[(1 << 23) + 51],
    dist[MAXN];
inline int read() {
  register int num = 0, neg = 1;
  register char ch = getchar();
  while (!isdigit(ch) && ch != '-') {
    ch = getchar();
  }
  if (ch == '-') {
    neg = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch - '0');
    ch = getchar();
  }
  return num * neg;
}
template <class T>
inline T Max(T x, T y) {
  return x > y ? x : y;
}
inline void addEdge(int from, int to, int dist) {
  ed[++tot].prev = last[from];
  ed[tot].to = to;
  ed[tot].dist = dist;
  last[from] = tot;
}
inline void dfs(int node, int f) {
  depth[node] = depth[fa[node] = f] + 1, size[node] = 1, l[node] = ++dfn,
  id[dfn] = node;
  int maxn = -1;
  for (register int i = last[node]; i; i = ed[i].prev) {
    if (ed[i].to != f) {
      dist[ed[i].to] = dist[node] ^ ed[i].dist;
      dfs(ed[i].to, node), size[node] += size[ed[i].to];
      if (size[ed[i].to] > maxn) {
        maxn = size[heavy[node] = ed[i].to];
      }
    }
  }
  r[node] = dfn;
}
inline void ddfs(int node, int state) {
  for (register int i = last[node]; i; i = ed[i].prev) {
    if (ed[i].to != fa[node] && ed[i].to != heavy[node]) {
      ddfs(ed[i].to, 0), res[node] = Max(res[node], res[ed[i].to]);
    }
  }
  if (heavy[node]) {
    ddfs(heavy[node], 1), res[node] = Max(res[node], res[heavy[node]]);
  }
  if (barrel[dist[node]]) {
    res[node] = Max(res[node], barrel[dist[node]] - depth[node]);
  }
  for (register int i = 0; i < 22; i++) {
    if (barrel[dist[node] ^ (1 << i)]) {
      res[node] = Max(res[node], barrel[dist[node] ^ (1 << i)] - depth[node]);
    }
  }
  barrel[dist[node]] = Max(depth[node], barrel[dist[node]]);
  for (register int i = last[node]; i; i = ed[i].prev) {
    if (ed[i].to != fa[node] && ed[i].to != heavy[node]) {
      for (register int j = l[ed[i].to]; j <= r[ed[i].to]; j++) {
        int x = id[j], kk = depth[x] - (depth[node] << 1);
        if (barrel[dist[x]]) {
          res[node] = Max(res[node], barrel[dist[x]] + kk);
        }
        for (register int k = 0; k < 22; k++) {
          if (barrel[dist[x] ^ (1 << k)]) {
            res[node] = Max(res[node], barrel[dist[x] ^ (1 << k)] + kk);
          }
        }
      }
      for (register int j = l[ed[i].to]; j <= r[ed[i].to]; j++) {
        barrel[dist[id[j]]] = Max(barrel[dist[id[j]]], depth[id[j]]);
      }
    }
  }
  if (!state) {
    for (register int i = l[node]; i <= r[node]; i++) {
      barrel[dist[id[i]]] = 0;
    }
  }
}
int main() {
  nc = read();
  for (register int i = 0; i < nc - 1; i++) {
    x = read(), cin >> ch;
    addEdge(i + 2, x, 1 << (ch - 'a')), addEdge(x, i + 2, 1 << (ch - 'a'));
  }
  dfs(1, 0), ddfs(1, 1);
  for (register int i = 1; i <= nc; i++) {
    printf("%d ", res[i]);
  }
}
