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;
int read() {
  int num = 0;
  bool flag = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') flag = 0;
  for (; c >= '0' && c <= '9'; c = getchar())
    num = (num << 1) + (num << 3) + c - '0';
  return flag ? num : -num;
}
const int N = 5e5 + 10;
struct dsu {
  struct cow {
    int x, y, z;
  } e[N];
  int head[N], tot, size[N], d[N];
  int Ans[N], ans, son[N], XOR[N], col[1 << 22];
  void inse(int xxxx, int yyyy, int zzzz) {
    e[++tot].x = head[xxxx];
    head[xxxx] = tot;
    e[tot].y = yyyy;
    e[tot].z = zzzz;
  }
  void dfs1(int x) {
    size[x] = 1;
    for (int i = head[x]; i; i = e[i].x) {
      int y = e[i].y;
      d[y] = d[x] + 1;
      XOR[y] = XOR[x] ^ (1 << e[i].z);
      dfs1(y);
      size[x] += size[y];
      if (size[y] > size[son[x]]) son[x] = y;
    }
  }
  void clear(int x) {
    col[XOR[x]] = 0;
    for (int i = head[x]; i; i = e[i].x) clear(e[i].y);
  }
  int double_deep;
  void get_max(int x) {
    if (col[XOR[x]]) ans = max(ans, d[x] + col[XOR[x]] - double_deep);
    for (int i = 0; i < 22; i++)
      if (col[XOR[x] ^ (1 << i)])
        ans = max(ans, d[x] + col[XOR[x] ^ (1 << i)] - double_deep);
  }
  void getmax(int x) {
    get_max(x);
    for (int i = head[x]; i; i = e[i].x) getmax(e[i].y);
  }
  void ex_change(int x) { col[XOR[x]] = max(d[x], col[XOR[x]]); }
  void exchange(int x) {
    ex_change(x);
    for (int i = head[x]; i; i = e[i].x) exchange(e[i].y);
  }
  void dfs2(int x, bool flag) {
    for (int i = head[x]; i; i = e[i].x)
      if (e[i].y != son[x]) dfs2(e[i].y, 0);
    if (son[x]) dfs2(son[x], 1);
    double_deep = d[x] << 1;
    for (int i = head[x]; i; i = e[i].x) ans = max(ans, Ans[e[i].y]);
    for (int i = head[x]; i; i = e[i].x)
      if (e[i].y != son[x]) getmax(e[i].y), exchange(e[i].y);
    get_max(x);
    ex_change(x);
    Ans[x] = ans;
    if (!flag) {
      clear(x);
      ans = 0;
    }
  }
  void before() {
    dfs1(1);
    dfs2(1, 1);
  }
} Tree;
int n;
int main() {
  n = read();
  for (int i = 2; i <= n; i++) {
    int x = read();
    char c;
    cin >> c;
    int z = c - 'a';
    Tree.inse(x, i, z);
  }
  Tree.before();
  for (int i = 1; i <= n; i++) printf("%d ", Tree.Ans[i]);
  return 0;
}
