#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, head[N], cnt, fa[N], dp[N], dep[N], sz[N], son[N], zt[N], dfn[N], idx,
    idfn[N];
int buc[1 << 23];
struct edge {
  int to, nxt, w;
} e[N];
void dfs(int u) {
  idfn[dfn[u] = ++idx] = u;
  sz[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    dep[e[i].to] = dep[u] + 1;
    zt[e[i].to] = zt[u] ^ (1 << e[i].w);
    dfs(e[i].to);
    sz[u] += sz[e[i].to];
    if (!son[u] || sz[son[u]] < sz[e[i].to]) son[u] = e[i].to;
  }
}
void dfs2(int u, bool tg) {
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != son[u]) dfs2(e[i].to, 0), dp[u] = max(dp[u], dp[e[i].to]);
  int res = 0;
  if (son[u]) {
    dfs2(son[u], 1), dp[u] = max(dp[u], dp[son[u]]);
    res = max(res, dep[u] + buc[zt[u]]);
    for (int i = 0; i < 22; ++i) res = max(res, dep[u] + buc[zt[u] ^ (1 << i)]);
  }
  buc[zt[u]] = max(buc[zt[u]], dep[u]);
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != son[u]) {
      int l = dfn[e[i].to], r = l + sz[e[i].to] - 1;
      for (int x = l; x <= r; ++x) {
        int s = zt[idfn[x]];
        res = max(res, dep[idfn[x]] + buc[s]);
        for (int y = 0; y < 22; ++y)
          res = max(res, dep[idfn[x]] + buc[s ^ (1 << y)]);
      }
      for (int x = l; x <= r; ++x) {
        int s = zt[idfn[x]];
        buc[s] = max(buc[s], dep[idfn[x]]);
      }
    }
  dp[u] = max(dp[u], res - 2 * dep[u]);
  if (!tg)
    for (int i = dfn[u]; i < dfn[u] + sz[u]; ++i) buc[zt[idfn[i]]] = -1e8;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (int i = 0; i < 1 << 23; ++i) buc[i] = -1e8;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    char c;
    cin >> fa[i] >> c;
    e[++cnt] = (edge){i, head[fa[i]], c - 'a'}, head[fa[i]] = cnt;
  }
  dfs(1);
  dfs2(1, 0);
  for (int i = 1; i <= n; ++i) cout << dp[i] << ' ';
  return 0;
}
