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 N = 500000 + 77, L = 22, inf = 1000000000;
int n, S[1 << L], dis[N], A[N], T[N], sz[N], ans = -inf;
vector<pair<int, int> > a[N];
vector<int> V;
void Add(int v) {
  V.push_back(T[v]);
  S[T[v]] = max(S[T[v]], dis[v]);
  for (auto x : a[v]) {
    Add(x.first);
  }
}
void Get(int v, int root) {
  for (int i = 0; i < L; i++) {
    int msk = (T[v] ^ (1 << i));
    ans = max(ans, S[msk] + dis[v] - 2 * dis[root]);
  }
  ans = max(ans, S[T[v]] + dis[v] - 2 * dis[root]);
  for (auto x : a[v]) {
    Get(x.first, root);
  }
}
void Clear() {
  for (int v : V) {
    S[v] = -inf;
  }
  ans = -inf;
  V.clear();
}
void dfs(int v) {
  if (sz[v] == 1) {
    Add(v);
    return;
  }
  int id = 0, Mx = 0;
  for (auto x : a[v]) {
    int u = x.first;
    if (sz[u] > Mx) {
      Mx = sz[u];
      id = u;
    }
  }
  for (auto x : a[v]) {
    int u = x.first;
    if (u == id) {
      continue;
    }
    dfs(u);
    Clear();
  }
  dfs(id);
  A[v] = A[id];
  for (auto x : a[v]) {
    int u = x.first;
    if (u == id) {
      continue;
    }
    Get(u, v);
    Add(u);
    A[v] = max(A[v], A[u]);
  }
  for (int i = 0; i < L; i++) {
    int msk = (T[v] ^ (1 << i));
    ans = max(ans, S[msk] - dis[v]);
  }
  ans = max(ans, S[T[v]] - dis[v]);
  S[T[v]] = max(S[T[v]], dis[v]);
  V.push_back(T[v]);
  A[v] = max(A[v], ans);
}
void dfs_pre(int v) {
  for (auto x : a[v]) {
    int u = x.first, t = x.second;
    T[u] = T[v] ^ (1 << t);
    dis[u] = dis[v] + 1;
    dfs_pre(u);
    sz[v] += sz[u];
  }
  sz[v]++;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u;
    char c;
    cin >> u >> c;
    a[u].push_back(make_pair(i + 1, c - 'a'));
  }
  for (int i = 0; i < (1 << L); i++) {
    S[i] = -inf;
  }
  dfs_pre(1);
  dfs(1);
  for (int i = 1; i <= n; i++) {
    cout << A[i] << ' ';
  }
  return 0;
}
