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;
void dout() { cerr << "\n"; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
int bit(signed x) { return __builtin_popcount(x); }
int bit(long long x) { return __builtin_popcountll(x); }
const int N = 5e5 + 7, M = 22, inf = 1e9;
int n, m[N], h[N], sz[N], mx[(1 << (M + 1))], ans[N];
vector<pair<int, int> > q[N];
void precalc(int v, int p) {
  sz[v] = 1;
  for (auto i : q[v]) {
    int to = i.first, c = i.second;
    if (to == p) {
      continue;
    }
    m[to] = (m[v] ^ (1 << c));
    h[to] = h[v] + 1;
    precalc(to, v);
    sz[v] += sz[to];
  }
}
void add(int v) { mx[m[v]] = max(mx[m[v]], h[v]); }
void dfs_add(int v, int p) {
  add(v);
  for (auto i : q[v]) {
    int to = i.first;
    if (to == p) {
      continue;
    }
    dfs_add(to, v);
  }
}
void del(int v) { mx[m[v]] = -inf; }
void dfs_del(int v, int p) {
  del(v);
  for (auto i : q[v]) {
    int to = i.first;
    if (to == p) {
      continue;
    }
    dfs_del(to, v);
  }
}
void calc(int v, int x) {
  ans[v] = max(ans[v], h[x] + mx[m[x]] - 2 * h[v]);
  for (int i = 0; i < M; i++) {
    ans[v] = max(ans[v], h[x] + mx[(1 << i) ^ m[x]] - 2 * h[v]);
  }
}
void dfs_calc(int v, int x, int p) {
  calc(v, x);
  for (auto i : q[x]) {
    int to = i.first;
    if (to == p) {
      continue;
    }
    dfs_calc(v, to, x);
  }
}
void dfs(int v, int p, bool cl) {
  int big = -1;
  for (auto i : q[v]) {
    int to = i.first;
    if (to == p) {
      continue;
    }
    if (big == -1 || sz[to] > sz[big]) {
      big = to;
    }
  }
  for (auto i : q[v]) {
    int to = i.first;
    if (to == p || to == big) {
      continue;
    }
    dfs(to, v, true);
    ans[v] = max(ans[v], ans[to]);
  }
  if (big != -1) {
    dfs(big, v, false);
    ans[v] = max(ans[v], ans[big]);
  }
  for (auto i : q[v]) {
    int to = i.first;
    if (to == p || to == big) {
      continue;
    }
    dfs_calc(v, to, v);
    dfs_add(to, v);
  }
  calc(v, v);
  add(v);
  if (cl) {
    dfs_del(v, p);
  }
}
void solve(int tc) {
  for (int i = 0; i < (1 << M); i++) {
    mx[i] = -inf;
  }
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    char c;
    cin >> x >> c;
    q[i].push_back({x, (c - 'a')});
    q[x].push_back({i, (c - 'a')});
  }
  precalc(1, 1);
  dfs(1, 1, false);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  for (int i = 0; i < tc; i++) {
    solve(i);
  }
}
