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>
int const N = 500000;
int const S = (1 << 23) - 1;
int const NINF = std::numeric_limits<int>::min() / 2;
struct Edge {
  int to;
  int next;
  int letter;
  Edge(int t = 0, int n = 0, int l = 0) : to(t), next(n), letter(l) {}
};
Edge edges[N + 1];
int edges_top;
int node[N + 1];
int number[N + 1];
int heavy_son[N + 1];
int cnt[S + 1];
int answers[N + 1];
int dist[N + 1];
int depth[N + 1];
int ans;
void add(int, int, int);
void dfs(int, int);
void solve(int, int);
void add_to_cnt(int, int);
void add_to_ans(int, int);
void clear(int, int, int);
void clear(int root, int father) {
  cnt[dist[root]] = NINF;
  for (int i = node[root]; i; i = edges[i].next) {
    int to = edges[i].to;
    if (to != father) {
      clear(to, root);
    }
  }
}
void add_to_ans(int root, int father) {
  ans = std::max(ans, depth[root] + cnt[dist[root]]);
  for (int i = 0; i <= 22; i++) {
    ans = std::max(ans, depth[root] + cnt[dist[root] ^ (1 << i)]);
  }
  for (int i = node[root]; i; i = edges[i].next) {
    int to = edges[i].to;
    if (to != father) {
      add_to_ans(to, root);
    }
  }
}
void add_to_cnt(int root, int father) {
  cnt[dist[root]] = std::max(cnt[dist[root]], depth[root]);
  for (int i = node[root]; i; i = edges[i].next) {
    int to = edges[i].to;
    if (to != father) {
      add_to_cnt(to, root);
    }
  }
}
void solve(int root, int father) {
  for (int i = node[root]; i; i = edges[i].next) {
    int to = edges[i].to;
    if (to != father && to != heavy_son[root]) {
      solve(to, root);
      answers[root] = std::max(answers[root], answers[to]);
      clear(to, root);
      ::ans = 0;
    }
  }
  if (heavy_son[root]) {
    solve(heavy_son[root], root);
    answers[root] = std::max(answers[root], answers[heavy_son[root]]);
  }
  ::ans = 0;
  for (int i = node[root]; i; i = edges[i].next) {
    int to = edges[i].to;
    if (to != father && to != heavy_son[root]) {
      add_to_ans(to, root);
      add_to_cnt(to, root);
    }
  }
  ::ans -= 2 * depth[root];
  cnt[dist[root]] = std::max(cnt[dist[root]], depth[root]);
  ::ans = std::max(::ans, cnt[dist[root]] - depth[root]);
  for (int i = 0; i <= 22; i++) {
    ::ans = std::max(::ans, cnt[dist[root] ^ (1 << i)] - depth[root]);
  }
  answers[root] = std::max(answers[root], ::ans);
}
void dfs(int root, int father) {
  depth[root] = depth[father] + 1;
  number[root] = 1;
  for (int i = node[root]; i; i = edges[i].next) {
    int to = edges[i].to;
    if (to != father) {
      dist[to] = dist[root] ^ (1 << edges[i].letter);
      dfs(to, root);
      number[root] += number[to];
      if (number[to] > number[heavy_son[root]]) {
        heavy_son[root] = to;
      }
    }
  }
}
void add(int a, int b, int l) {
  edges_top++;
  edges[edges_top] = Edge(b, node[a], l);
  node[a] = edges_top;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int n;
  std::cin >> n;
  for (int i = 2; i <= n; i++) {
    int fa;
    char c;
    std::cin >> fa >> c;
    add(fa, i, c - 'a');
  }
  for (int i = 0; i <= S; i++) {
    cnt[i] = NINF;
  }
  dfs(1, 0);
  solve(1, 0);
  for (int i = 1; i <= n; i++) {
    std::cout << answers[i] << ' ';
  }
  return 0;
}
