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 maxN = 500001;
const int maxCODE = 1 << 22;
const int INF = numeric_limits<int>::max() / 2;
int n, tdf;
int le[maxN];
int ri[maxN];
int ve[maxN];
int code[maxN];
int dist[maxN];
int weight[maxN];
vector<pair<int, int>> g[maxN];
void dfsPrep(int x) {
  weight[x] = 1;
  tdf++;
  le[x] = tdf;
  ve[tdf] = x;
  for (auto &e : g[x]) {
    int y, c;
    tie(y, c) = e;
    code[y] = code[x] ^ (1 << c);
    dist[y] = dist[x] + 1;
    dfsPrep(y);
    weight[x] += weight[y];
  }
  ri[x] = tdf;
}
int sol[maxN];
int sack[maxCODE];
inline int findSol(int x, int r) {
  int c = code[x];
  int s = 0;
  for (int i = 0; i < 22; i++)
    s = max(s, dist[x] + sack[c ^ (1 << i)] - 2 * dist[r]);
  s = max(s, dist[x] + sack[c] - 2 * dist[r]);
  return s;
}
int dfsSolve(int x, bool clear) {
  int size = 0;
  int son = 0;
  for (auto &e : g[x])
    if (size < weight[e.first]) size = weight[e.first], son = e.first;
  if (son != 0) {
    for (auto &e : g[x])
      if (e.first != son) sol[x] = max(sol[x], dfsSolve(e.first, true));
    sol[x] = max(sol[x], dfsSolve(son, false));
    for (auto &e : g[x]) {
      int y = e.first;
      if (y != son) {
        for (int i = le[y]; i <= ri[y]; i++)
          sol[x] = max(sol[x], findSol(ve[i], x));
        for (int i = le[y]; i <= ri[y]; i++)
          sack[code[ve[i]]] = max(sack[code[ve[i]]], dist[ve[i]]);
      }
    }
  }
  sol[x] = max(sol[x], findSol(x, x));
  sack[code[x]] = max(sack[code[x]], dist[x]);
  if (clear == true)
    for (int i = le[x]; i <= ri[x]; i++) sack[code[ve[i]]] = (-1) * INF;
  return sol[x];
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int f;
    char c;
    scanf("%d %c", &f, &c);
    g[f].emplace_back(i, c - 'a');
  }
  dfsPrep(1);
  fill(sack, sack + maxCODE, (-1) * INF);
  dfsSolve(1, false);
  for (int i = 1; i <= n; i++) printf("%d ", sol[i]);
  printf("\n");
  return 0;
}
