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;
int ans[500005];
int lenOff[500005], mask[500005];
int len[(1 << 22) + 2];
int sub[500005];
vector<int> g[500005], e[500005];
void Add(int u, int root, int curMask, int l) {
  len[(curMask ^ mask[root])] =
      max(len[(curMask ^ mask[root])], l - lenOff[root]);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    Add(v, root, (curMask ^ (1 << e[u][i])), l + 1);
  }
}
void Remove(int u, int root, int curMask, int l) {
  len[(curMask ^ mask[root])] = -1000000000;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    Remove(v, root, (curMask ^ (1 << e[u][i])), l + 1);
  }
}
void addAnswer(int u, int root, int curMask, int l) {
  ans[root] = max(ans[root], len[(curMask ^ mask[root])] + lenOff[root] + l);
  for (int i = 0; i < 22; i++) {
    int m = (curMask ^ (1 << i));
    ans[root] = max(ans[root], len[m ^ mask[root]] + lenOff[root] + l);
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    addAnswer(v, root, (curMask ^ (1 << e[u][i])), l + 1);
  }
}
void dfs(int u, bool keep) {
  bool hasChild = ((int)g[u].size() > 0);
  for (int i = 1; i < g[u].size(); i++) {
    dfs(g[u][i], 0);
  }
  if (hasChild) {
    int bigChild = g[u][0];
    dfs(bigChild, 1);
    mask[u] = (mask[bigChild] ^ (1 << e[u][0]));
    lenOff[u] = lenOff[bigChild] + 1;
  }
  len[mask[u]] = max(len[mask[u]], -lenOff[u]);
  for (int i = 1; i < g[u].size(); i++) {
    addAnswer(g[u][i], u, (1 << e[u][i]), 1);
    Add(g[u][i], u, (1 << e[u][i]), 1);
  }
  ans[u] = max(ans[u], 0);
  ans[u] = max(ans[u], len[mask[u]] + lenOff[u]);
  for (int i = 0; i < 22; i++) {
    ans[u] = max(ans[u], len[(mask[u] ^ (1 << i))] + lenOff[u]);
  }
  for (auto v : g[u]) ans[u] = max(ans[u], ans[v]);
  if (keep == 0) Remove(u, u, 0, 0);
}
void dfsSize(int u) {
  sub[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    dfsSize(v);
    sub[u] += sub[v];
    if (sub[v] > sub[g[u][0]]) {
      swap(g[u][0], g[u][i]);
      swap(e[u][0], e[u][i]);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    char s[4];
    scanf("%d %s", &p, s);
    g[p].push_back(i);
    e[p].push_back(s[0] - 'a');
  }
  for (int i = 0; i < (1 << 22); i++) len[i] = -1000000000;
  dfsSize(1);
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
  return 0;
}
