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 MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
template <class T>
inline T isqrt(T k) {
  T r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
template <class T>
inline T icbrt(T k) {
  T r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
const int maxn = 500000 + 10;
const int maxc = 22;
int n;
vector<int> adj[maxn];
string w[maxn];
int size[maxn];
int lev[maxn];
vector<pair<int, int> >* f[maxn];
multiset<int> g[1 << maxc];
int mx[1 << maxc];
int ans[maxn];
void dfs1(int u, int p = -1) {
  size[u] = 1;
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p) {
      lev[v] = lev[u] + 1;
      dfs1(v, u);
      size[u] += size[v];
    }
  }
}
inline void add(int key, int val) {
  g[key].insert(val);
  mx[key] = *g[key].rbegin();
}
inline void rem(int key, int val) {
  g[key].erase(g[key].find(val));
  mx[key] = int((g[key]).size()) ? *g[key].rbegin() : -INF;
}
void dfs2(int u, int p = -1, int key = 0, int keep = 0) {
  pair<int, int> best = make_pair(-INF, -INF);
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p) {
      chkmax(best, make_pair(size[v], v));
    }
  }
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p && v != best.second) {
      dfs2(v, u, key ^ (1 << w[v][0] - 'a'), 0);
      chkmax(ans[u], ans[v]);
    }
  }
  if (best.second != -INF) {
    dfs2(best.second, u, key ^ (1 << w[best.second][0] - 'a'), 1);
    chkmax(ans[u], ans[best.second]);
    f[u] = f[best.second];
  } else {
    f[u] = new vector<pair<int, int> >;
  }
  chkmax(ans[u], mx[key] - lev[u]);
  for (int i = (0); i < (maxc); i++) {
    chkmax(ans[u], mx[key ^ (1 << i)] - lev[u]);
  }
  f[u]->push_back(make_pair(key, lev[u]));
  add(key, lev[u]);
  for (int i = (0); i < (int((adj[u]).size())); i++) {
    int v = adj[u][i];
    if (v != p && v != best.second) {
      for (int j = (0); j < (int((*f[v]).size())); j++) {
        int key = (*f[v])[j].first;
        int val = (*f[v])[j].second;
        chkmax(ans[u], mx[key] + val - 2 * lev[u]);
        for (int k = (0); k < (maxc); k++) {
          chkmax(ans[u], mx[key ^ (1 << k)] + val - 2 * lev[u]);
        }
      }
      for (int j = (0); j < (int((*f[v]).size())); j++) {
        int key = (*f[v])[j].first;
        int val = (*f[v])[j].second;
        f[u]->push_back(make_pair(key, val));
        add(key, val);
      }
    }
  }
  if (!keep) {
    for (int i = (0); i < (int((*f[u]).size())); i++) {
      int key = (*f[u])[i].first;
      int val = (*f[u])[i].second;
      rem(key, val);
    }
  }
}
void solve() {
  fill_n(mx, 1 << maxc, -INF);
  cin >> n;
  for (int i = (0); i < (n - 1); i++) {
    int u;
    cin >> u >> w[i + 1];
    u--;
    adj[u].push_back(i + 1);
  }
  dfs1(0), dfs2(0);
  for (int i = (0); i < (n); i++) cout << ans[i] << " \n"[i == n - 1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
