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;
template <typename T>
inline T fetch() {
  T ret;
  cin >> ret;
  return ret;
}
template <typename T>
inline vector<T> fetch_vec(int sz) {
  vector<T> ret(sz);
  for (auto& it : ret) cin >> it;
  return ret;
}
template <typename T>
inline void makeUnique(vector<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <typename T>
inline T max_(T a, T b) {
  if (a > b) return a;
  return b;
}
template <typename T>
inline T min_(T a, T b) {
  if (a < b) return a;
  return b;
}
void file() {}
void Match() {}
const int N = 5e5 + 5;
vector<pair<int, int> > G[N];
int son[N], Size[N], deep[N], ans[N];
int in[N], out[N], pos = 0, id[N];
int f[(1 << 22) + 5], dis[(1 << 22) + 5];
void dfs(int u, int fat) {
  deep[u] = deep[fat] + 1;
  Size[u]++;
  in[u] = ++pos;
  id[pos] = u;
  for (auto it : G[u]) {
    int v = it.first, w = it.second;
    if (v == fat) continue;
    dis[v] = dis[u] ^ w;
    dfs(v, u);
    Size[u] += Size[v];
    if (Size[v] > Size[son[u]]) son[u] = v;
  }
  out[u] = pos;
}
void cal(int u, int root) {
  ans[root] = max(ans[root], f[dis[u]] + deep[u] - deep[root] * 2);
  for (int i = 0; i < 22; i++) {
    int num = dis[u] ^ (1 << i);
    ans[root] = max(ans[root], f[num] + deep[u] - deep[root] * 2);
  }
}
void dfs2(int u, int fat, int opt) {
  for (auto it : G[u]) {
    int v = it.first, w = it.second;
    if (v == fat || v == son[u]) continue;
    dfs2(v, u, 0);
    ans[u] = max(ans[u], ans[v]);
  }
  if (son[u]) {
    dfs2(son[u], u, 1), ans[u] = max(ans[u], ans[son[u]]);
  }
  cal(u, u);
  f[dis[u]] = max(f[dis[u]], deep[u]);
  for (auto it : G[u]) {
    int v = it.first, w = it.second;
    if (v == fat || v == son[u]) continue;
    for (int i = in[v]; i <= out[v]; i++) cal(id[i], u);
    for (int i = in[v]; i <= out[v]; i++) {
      int num = dis[id[i]];
      f[num] = max(f[num], deep[id[i]]);
    }
  }
  if (!opt) {
    for (int i = in[u]; i <= out[u]; i++) {
      f[dis[id[i]]] = -0x3f3f3f3f;
    }
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  file();
  int n;
  cin >> n;
  for (int v = 2; v <= n; v++) {
    int u;
    char c;
    cin >> u >> c;
    int w = 1 << (c - 'a');
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  memset(f, -0x3f, sizeof(f));
  ;
  dfs(1, 0);
  dfs2(1, 0, 1);
  for (int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
  Match();
  return 0;
}
