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>
long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
int fir[500010], dis[500010], nxt[500010], id;
char w[500010];
void link(int a, int b, char c) {
  nxt[++id] = fir[a], fir[a] = id, dis[id] = b, w[id] = c;
}
int QAQ[100], m;
struct uo_map {
  std::unordered_map<int, int> s;
  int tagk, tags;
  uo_map() { tagk = tags = 0; }
  int size() { return s.size(); }
  int get(int x) {
    if (s.count(x ^ tagk)) return s[x ^ tagk] + tags;
    return -1e9;
  }
  void set(int x, int o) {
    if (s.count(x ^ tagk))
      s[x ^ tagk] = std::max(s[x ^ tagk], o - tags);
    else
      s[x ^ tagk] = o - tags;
  }
  void swap(uo_map& B) {
    s.swap(B.s), std::swap(tagk, B.tagk), std::swap(tags, B.tags);
  }
} M[500010];
void Union(uo_map& A, uo_map& B, int& res, int o) {
  if (A.size() > B.size()) {
    for (auto [x, y] : B.s)
      for (int i = 1; i <= m; ++i)
        res = std::max(res, A.get(x ^ B.tagk ^ QAQ[i] ^ o) + y + B.tags + 1);
    for (auto [x, y] : B.s) A.set(x ^ B.tagk ^ o, y + B.tags + 1);
  } else {
    A.swap(B);
    A.tagk ^= o;
    ++A.tags;
    for (auto [x, y] : B.s)
      for (int i = 1; i <= m; ++i)
        res = std::max(res, A.get(x ^ B.tagk ^ QAQ[i]) + y + B.tags);
    for (auto [x, y] : B.s) A.set(x ^ B.tagk, y + B.tags);
  }
}
int ans[500010];
void dfs(int x) {
  M[x].set(0, 0);
  for (int i = fir[x]; i; i = nxt[i]) {
    dfs(dis[i]), ans[x] = std::max(ans[x], ans[dis[i]]);
    Union(M[x], M[dis[i]], ans[x], 1 << w[i]);
  }
}
int main() {
  QAQ[m = 1] = 0;
  for (int i = 0; i < 22; ++i) QAQ[++m] = 1 << i;
  int n = gi(), fa;
  char ch;
  for (int i = 2; i <= n; ++i) fa = gi(), ch = getchar(), link(fa, i, ch - 'a');
  dfs(1);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
