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 long long MAXN = 5e5 + 10;
const long long Sigma = 22;
const long long INF = 1e9 + 10;
vector<pair<int, int> > s[MAXN];
vector<pair<int, char> > vertex[MAXN];
int w[1 << Sigma];
int y[1 << Sigma];
int x[MAXN];
int p[MAXN];
int dp[MAXN];
int subtree[MAXN];
long long ID = 1;
bool cmp(const pair<long long, long long>& a,
         const pair<long long, long long>& b) {
  return subtree[a.first] < subtree[b.first];
}
void dsu(long long a, long long b, long long v) {
  for (long long i = 0; i < s[a].size(); i++) {
    long long k = s[a][i].first;
    k ^= x[a];
    for (long long j = 0; j < Sigma; j++) {
      if (w[(k ^ (1 << j)) ^ x[b]] == ID) {
        dp[v] =
            max(dp[v], y[k ^ (1 << j) ^ x[b]] + p[b] + s[a][i].second + p[a]);
      }
    }
    if (w[k ^ x[b]] == ID) {
      dp[v] = max(dp[v], y[k ^ x[b]] + p[b] + s[a][i].second + p[a]);
    }
  }
  while (s[a].size() > 0) {
    long long k = s[a].back().first;
    k ^= x[a];
    if (w[k ^ x[b]] == ID) {
      y[k ^ x[b]] = max(y[k ^ x[b]], s[a].back().second + p[a] - p[b]);
    } else {
      w[k ^ x[b]] = ID;
      y[k ^ x[b]] = s[a].back().second + p[a] - p[b];
    }
    s[b].push_back(make_pair(k ^ x[b], y[k ^ x[b]]));
    s[a].pop_back();
  }
}
void dfs(long long v) {
  subtree[v] = 1;
  for (long long i = 0; i < vertex[v].size(); i++) {
    dfs(vertex[v][i].first);
    subtree[v] += subtree[vertex[v][i].first];
  }
}
void main_dfs(long long v) {
  dp[v] = 0;
  long long k = 0;
  for (long long i = 0; i < vertex[v].size(); i++) {
    ID++;
    main_dfs(vertex[v][i].first);
    x[vertex[v][i].first] ^= (1 << (vertex[v][i].second - 'a'));
    p[vertex[v][i].first]++;
    if (w[x[vertex[v][i].first]] == ID) {
      y[x[vertex[v][i].first]] =
          max(y[x[vertex[v][i].first]], -p[vertex[v][i].first]);
    } else {
      w[x[vertex[v][i].first]] = ID;
      y[x[vertex[v][i].first]] = -p[vertex[v][i].first];
    }
    s[vertex[v][i].first].push_back(
        make_pair(x[vertex[v][i].first], y[x[vertex[v][i].first]]));
    dp[v] = max(dp[vertex[v][i].first], dp[v]);
    k = vertex[v][i].first;
  }
  for (long long i = 0; i < vertex[v].size(); i++) {
    if (vertex[v][i].first != k) {
      dsu(vertex[v][i].first, k, v);
    }
  }
  if (k != 0) {
    s[0].push_back(make_pair(0, 0));
    dsu(0, k, v);
    p[v] = p[k];
    x[v] = x[k];
    s[v].swap(s[k]);
  } else {
    y[0] = 0;
    w[0] = ID;
    s[v].push_back(make_pair(0, 0));
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 2; i <= n; i++) {
    long long v;
    char a;
    cin >> v >> a;
    vertex[v].push_back(make_pair(i, a));
  }
  dfs(1);
  for (long long i = 1; i <= n; i++) {
    sort(vertex[i].begin(), vertex[i].end(), cmp);
  }
  fill(y, y + (1 << Sigma), -INF);
  fill(w, w + (1 << Sigma), -INF);
  main_dfs(1);
  for (long long i = 1; i <= n; i++) {
    cout << dp[i] << " ";
  }
}
