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 sz = 5e5 + 5, msz = 1 << 22;
int a[sz], sbz[sz], depth[sz], msk[sz];
int cnt[msz], when[msz], ans[sz], curt, offt, now;
vector<int> g[sz], dope;
void got(int nd, int rt) {
  rt = depth[rt];
  int m = msk[nd], d = depth[nd];
  if (offt < when[m]) now = max(now, cnt[m] + d - 2 * rt);
  for (int j = 0; j < 22; j++) {
    int mm = m ^ (1 << j);
    if (offt < when[mm]) now = max(now, cnt[mm] + d - 2 * rt);
  }
}
void chang(int nd) {
  int m = msk[nd], d = depth[nd];
  if (cnt[m] < d || offt >= when[m]) cnt[m] = d, when[m] = curt;
}
void fnc(int u, int cut) {
  for (int v : g[u])
    if (v ^ cut) {
      queue<int> q, qt;
      q.push(v);
      while (!q.empty()) {
        int nd = q.front();
        q.pop();
        qt.push(nd);
        for (int ndv : g[nd]) q.push(ndv);
        got(nd, u);
      }
      while (!qt.empty()) {
        int nd = qt.front();
        qt.pop();
        chang(nd);
      }
    }
  got(u, u);
  chang(u);
}
void dfs(int u = 1, bool keep = 0) {
  int mx = 0, bigc = 0;
  for (int v : g[u])
    if (sbz[v] > mx) mx = sbz[v], bigc = v;
  for (int v : g[u])
    if (v ^ bigc) dfs(v);
  if (bigc) dfs(bigc, 1);
  now = 0, ++curt;
  fnc(u, bigc);
  for (int v : g[u]) now = max(now, ans[v]);
  ans[u] = now;
  if (!keep) offt = curt;
}
int getsbz(int u = 1, int lvl = 1, int m = 0) {
  sbz[u] = 1, depth[u] = lvl++, msk[u] = (m ^= a[u]);
  for (int v : g[u]) sbz[u] += getsbz(v, lvl, m);
  return sbz[u];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int u, v = i;
    char ch;
    scanf("%d %c", &u, &ch);
    g[u].push_back(v);
    a[v] = 1 << (ch - 'a');
  }
  getsbz();
  dfs();
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
