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 = 500010;
const int INF = 1000000010;
const int EXP = 1024 * 1024 * 4 + 10;
int n;
int curTime;
int dp[MAXN];
int val[MAXN];
int prof[MAXN];
int maxSz[EXP];
int sub[MAXN];
int tin[MAXN];
int tout[MAXN];
int node[MAXN];
vector<int> adj[MAXN];
vector<int> weight[MAXN];
void calculateValue(int cur, int node, int k) {
  int szPath = maxSz[k] + prof[node];
  szPath -= 2 * prof[cur];
  dp[cur] = max(dp[cur], szPath);
}
void merge(int cur, int node) {
  for (int c = 0; c < 22; c++) calculateValue(cur, node, val[node] ^ (1 << c));
  calculateValue(cur, node, val[node]);
}
void update(int node) {
  int& sz = maxSz[val[node]];
  sz = max(sz, prof[node]);
}
void DFSSack(int cur, bool keep = false) {
  if (cur == 0) return;
  int heavySon = 0;
  for (int i = 0; i < adj[cur].size(); i++) {
    int viz = adj[cur][i];
    if (heavySon == 0)
      heavySon = viz;
    else if (sub[viz] > sub[heavySon])
      heavySon = viz;
  }
  for (int i = 0; i < adj[cur].size(); i++) {
    int viz = adj[cur][i];
    if (heavySon != viz) DFSSack(viz);
  }
  DFSSack(heavySon, true);
  dp[cur] = dp[heavySon];
  merge(cur, cur);
  update(cur);
  for (int i = 0; i < adj[cur].size(); i++) {
    int viz = adj[cur][i];
    if (viz == heavySon) continue;
    dp[cur] = max(dp[cur], dp[viz]);
    for (int j = tin[viz]; j <= tout[viz]; j++) merge(cur, node[j]);
    for (int j = tin[viz]; j <= tout[viz]; j++) update(node[j]);
  }
  if (keep) return;
  for (int i = tin[cur]; i <= tout[cur]; i++) maxSz[val[node[i]]] = -INF;
}
void DFSInit(int cur) {
  sub[cur] = 1;
  tin[cur] = ++curTime;
  node[curTime] = cur;
  for (int i = 0; i < adj[cur].size(); i++) {
    int viz = adj[cur][i];
    int w = weight[cur][i];
    val[viz] = val[cur];
    val[viz] ^= (1 << w);
    prof[viz] = prof[cur] + 1;
    DFSInit(viz);
    sub[cur] += sub[viz];
  }
  tout[cur] = curTime;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < EXP; i++) maxSz[i] = -INF;
  for (int i = 2; i <= n; i++) {
    int p;
    char w;
    scanf("%d %c", &p, &w);
    adj[p].push_back(i);
    weight[p].push_back(w - 'a');
  }
  DFSInit(1);
  DFSSack(1);
  for (int i = 1; i <= n; i++) printf("%d ", dp[i]);
}
