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 Max = 5e5 + 5, Mod = 1e9 + 7;
int n, sz[Max], big[Max];
vector<int> G[Max];
int XOR[Max], H[Max], a[Max];
void Get(int u, int p) {
  H[u] = H[p] + 1;
  sz[u] = 1;
  int b = 0, bsz = 0;
  for (auto v : G[u]) {
    XOR[v] = (XOR[u] ^ (1 << a[v]));
    Get(v, u);
    sz[u] += sz[v];
    if (bsz < sz[v]) b = v, bsz = sz[v];
  }
  big[u] = b;
}
int mx[1 << 22 | 5];
int ans[Max];
void add(int u, int p, int val) {
  int& v = mx[XOR[u]];
  if (val == -1)
    v = 0;
  else if (val == 0)
    v = max(v, H[u]);
  else {
    int x = XOR[u];
    if (mx[x] > 0) ans[val] = max(ans[val], H[u] + mx[x] - 2 * H[val]);
    for (int i = 0; i < 22; i++) {
      x = (XOR[u] ^ (1 << i));
      if (mx[x] > 0) ans[val] = max(ans[val], H[u] + mx[x] - 2 * H[val]);
    }
  }
  for (auto v : G[u]) add(v, u, val);
}
void DFS(int u, int p, bool keep) {
  for (auto v : G[u])
    if (v != big[u]) DFS(v, u, 0);
  if (big[u] > 0) DFS(big[u], u, 1);
  int x = XOR[u];
  int& aa = ans[u];
  if (mx[x] > 0) aa = max(aa, mx[x] - H[u]);
  for (int i = 0; i < 22; i++) {
    x = (XOR[u] ^ (1 << i));
    if (mx[x] > 0) aa = max(aa, mx[x] - H[u]);
  }
  x = XOR[u];
  mx[x] = max(mx[x], H[u]);
  for (auto v : G[u])
    if (v != big[u]) {
      add(v, u, u);
      add(v, u, 0);
    }
  if (keep == 0) add(u, p, -1);
  for (auto v : G[u])
    if (v != p) ans[u] = max(ans[u], ans[v]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    char c;
    cin >> x >> c;
    G[x].push_back(i);
    a[i] = (c - 'a');
  }
  Get(1, 1);
  DFS(1, 1, 1);
  for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
  cout << '\n';
  return 0;
}
