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 = 500000 + 123;
const int INF = 1e9 + 123;
int n;
vector<pair<int, int> > V[maxn];
void ReadData() {
  cin >> n;
  for (int i = 2, _b = n; i <= _b; ++i) {
    int p;
    char c;
    cin >> p >> c;
    int x = c - 'a';
    V[p].push_back(pair<int, int>(i, x));
  }
}
int mask[maxn], tin[maxn], tout[maxn], sta[maxn];
int level[maxn], chil[maxn], timer;
void preDfs(int u) {
  tin[u] = ++timer;
  sta[timer] = u;
  chil[u] = 1;
  for (auto x : V[u]) {
    int v = x.first, c = x.second;
    mask[v] = mask[u] ^ (1 << c);
    level[v] = level[u] + 1;
    preDfs(v);
    chil[u] += chil[v];
  }
  tout[u] = timer;
}
int res[maxn];
int dp[1 << 24];
vector<int> rem;
void pushMask(int mask, int val) {
  if (dp[mask] == -INF) rem.push_back(mask);
  dp[mask] = max(dp[mask], val);
}
void resetRem() {
  for (int x : rem) dp[x] = -INF;
  rem.clear();
}
void dfs(int u, bool keep) {
  int bigChil = -1;
  for (auto x : V[u]) {
    if (bigChil == -1 || chil[bigChil] < chil[x.first]) bigChil = x.first;
  }
  res[u] = 0;
  for (auto x : V[u]) {
    int v = x.first;
    if (v == bigChil) continue;
    dfs(v, 0);
    res[u] = max(res[u], res[v]);
  }
  if (bigChil != -1) dfs(bigChil, 1);
  if (bigChil != -1) res[u] = max(res[u], res[bigChil]);
  for (auto x : V[u]) {
    int v = x.first;
    if (v == bigChil) continue;
    for (int i = tin[v], _b = tout[v]; i <= _b; ++i) {
      int z = sta[i];
      res[u] = max(res[u], level[z] + dp[mask[z]] - 2 * level[u]);
      for (int p = 0, _n = 23; p < _n; ++p) {
        res[u] = max(res[u], level[z] + dp[mask[z] ^ (1 << p)] - 2 * level[u]);
      }
    }
    for (int i = tin[v], _b = tout[v]; i <= _b; ++i) {
      int z = sta[i];
      pushMask(mask[z], level[z]);
    }
  }
  res[u] = max(res[u], dp[mask[u]] - level[u]);
  for (int p = 0, _n = 23; p < _n; ++p)
    res[u] = max(res[u], dp[mask[u] ^ (1 << p)] - level[u]);
  pushMask(mask[u], level[u]);
  if (!keep) resetRem();
}
void Process() {
  preDfs(1);
  for (int x = 0, _n = 1 << 23; x < _n; ++x) dp[x] = -INF;
  mask[1] = 0;
  dfs(1, 0);
  for (int i = 1, _b = n; i <= _b; ++i) cout << res[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ReadData();
  Process();
  return 0;
}
