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 N;
vector<vector<pair<int, int> > > adj;
vector<int> sz, tin, tout, invt;
vector<int> mask;
vector<int> dep;
int timer = 0;
void dfs1(int u) {
  tin[u] = timer++;
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    int c = adj[u][i].second;
    mask[v] = mask[u] ^ (1 << c);
    dep[v] = dep[u] + 1;
    dfs1(v);
    sz[u] += sz[v];
  }
  tout[u] = timer;
}
vector<int> cnt;
vector<int> ans;
void dfs2(int u, bool keep) {
  int mx = -1, big = -1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    if (mx < sz[v]) {
      mx = sz[v];
      big = v;
    }
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    if (v == big) continue;
    dfs2(v, 0);
    ans[u] = max(ans[u], ans[v]);
  }
  if (big != -1) {
    dfs2(big, 1);
    ans[u] = max(ans[u], ans[big]);
  }
  int pans = 0;
  if (cnt[mask[u]] != -1) pans = max(pans, cnt[mask[u]] - dep[u]);
  for (int i = 0; i < 22; i++) {
    if (cnt[mask[u] ^ (1 << i)] != -1)
      pans = max(pans, cnt[mask[u] ^ (1 << i)] - dep[u]);
  }
  cnt[mask[u]] = max(cnt[mask[u]], dep[u]);
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i].first;
    if (v == big) continue;
    for (int j = tin[v]; j < tout[v]; j++) {
      int x = invt[j];
      if (cnt[mask[x]] != -1)
        pans = max(pans, cnt[mask[x]] + dep[x] - 2 * dep[u]);
      for (int k = 0; k < 22; k++) {
        if (cnt[mask[x] ^ (1 << k)] != -1)
          pans = max(pans, cnt[mask[x] ^ (1 << k)] + dep[x] - 2 * dep[u]);
      }
    }
    for (int j = tin[v]; j < tout[v]; j++) {
      int x = invt[j];
      cnt[mask[x]] = max(cnt[mask[x]], dep[x]);
    }
  }
  if (!keep) {
    for (int i = tin[u]; i < tout[u]; i++) {
      int x = invt[i];
      cnt[mask[x]] = -1;
    }
  }
  ans[u] = max(ans[u], pans);
}
int main() {
  scanf("%d", &N);
  adj.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int p;
    char c;
    scanf("%d %c", &p, &c);
    p--;
    adj[p].push_back(pair<int, int>(i + 1, c - 'a'));
  }
  sz = tin = tout = vector<int>(N);
  dep = mask = vector<int>(N, 0);
  dfs1(0);
  invt.resize(N);
  for (int i = 0; i < N; i++) {
    invt[tin[i]] = i;
  }
  cnt = vector<int>((1 << 22), -1);
  ans = vector<int>(N, 0);
  dfs2(0, 0);
  for (int i = 0; i < N; i++) {
    printf("%d ", ans[i]);
  }
}
