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>
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
using namespace std;
class pa3 {
 public:
  int x;
  int y, z;
  pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
  bool operator<(const pa3 &p) const {
    if (x != p.x) return x < p.x;
    if (y != p.y) return y < p.y;
    return z < p.z;
  }
  bool operator>(const pa3 &p) const {
    if (x != p.x) return x > p.x;
    if (y != p.y) return y > p.y;
    return z > p.z;
  }
  bool operator==(const pa3 &p) const {
    return x == p.x && y == p.y && z == p.z;
  }
  bool operator!=(const pa3 &p) const {
    return !(x == p.x && y == p.y && z == p.z);
  }
};
class pa4 {
 public:
  int x;
  int y, z, w;
  pa4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {}
  bool operator<(const pa4 &p) const {
    if (x != p.x) return x < p.x;
    if (y != p.y) return y < p.y;
    if (z != p.z) return z < p.z;
    return w < p.w;
  }
  bool operator>(const pa4 &p) const {
    if (x != p.x) return x > p.x;
    if (y != p.y) return y > p.y;
    if (z != p.z) return z > p.z;
    return w > p.w;
  }
  bool operator==(const pa4 &p) const {
    return x == p.x && y == p.y && z == p.z && w == p.w;
  }
};
class pa2 {
 public:
  int x, y;
  pa2(int x = 0, int y = 0) : x(x), y(y) {}
  pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }
  pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }
  bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }
  bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }
  bool operator==(const pa2 &p) const {
    return abs(x - p.x) == 0 && abs(y - p.y) == 0;
  }
  bool operator!=(const pa2 &p) const {
    return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);
  }
};
string itos(int i) {
  ostringstream s;
  s << i;
  return s.str();
}
int gcd(int v, int b) {
  if (v == 0) return b;
  if (b == 0) return v;
  if (v > b) return gcd(b, v);
  if (v == b) return b;
  if (b % v == 0) return v;
  return gcd(v, b % v);
}
int mod;
int extgcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
pair<int, int> operator+(const pair<int, int> &l, const pair<int, int> &r) {
  return {l.first + r.first, l.second + r.second};
}
pair<int, int> operator-(const pair<int, int> &l, const pair<int, int> &r) {
  return {l.first - r.first, l.second - r.second};
}
int pr[10000100];
int inv[10000010];
int beki(int wa, int rr, int warukazu) {
  if (rr == 0) return 1 % warukazu;
  if (rr == 1) return wa % warukazu;
  wa %= warukazu;
  if (rr % 2 == 1)
    return ((long long)beki(wa, rr - 1, warukazu) * (long long)wa) % warukazu;
  long long zx = beki(wa, rr / 2, warukazu);
  return (zx * zx) % warukazu;
}
int comb(int nn, int rr) {
  if (rr < 0 || rr > nn || nn < 0) return 0;
  int r = pr[nn] * inv[rr];
  r %= mod;
  r *= inv[nn - rr];
  r %= mod;
  return r;
}
void gya(int ert) {
  pr[0] = 1;
  for (int i = 1; i <= ert; i++) {
    pr[i] = ((long long)pr[i - 1] * i) % mod;
  }
  inv[ert] = beki(pr[ert], mod - 2, mod);
  for (int i = ert - 1; i >= 0; i--) {
    inv[i] = (long long)inv[i + 1] * (i + 1) % mod;
  }
}
vector<pair<int, int> > G[500020];
int dp[1 << 22];
int sz[500020];
int memo[500020];
int ans[500020] = {};
vector<int> oi;
int P = 0;
int oi_in[500020];
int oi_out[500020];
int dep[500020];
int dfs_s(int r, int e = 0, int d = 0) {
  oi_in[r] = P;
  oi[P] = r;
  P++;
  dep[r] = d;
  sz[r] = 1;
  memo[r] = e;
  for (auto v : G[r]) sz[r] += dfs_s(v.first, e ^ (1 << v.second), d + 1);
  oi_out[r] = P;
  return sz[r];
}
vector<int> ve;
int ch(int r, int l) {
  int ma = -1;
  for (auto v : ve) {
    ma = max(ma, dp[memo[r] ^ v]);
  }
  if (ma == -1) return -1;
  return ma + dep[r] - 2 * dep[l];
}
void dfs(int r, bool keep) {
  int ma = -1;
  int hv = -1;
  for (auto v : G[r])
    if (ma < sz[v.first]) ma = sz[v.first], hv = v.first;
  for (auto v : G[r])
    if (v.first != hv) dfs(v.first, false);
  if (hv != -1) dfs(hv, true);
  ans[r] = max(ans[r], ch(r, r));
  dp[memo[r]] = max(dp[memo[r]], dep[r]);
  for (auto v : G[r])
    if (v.first != hv) {
      for (int i = oi_in[v.first]; i < oi_out[v.first]; i++)
        ans[r] = max(ans[r], ch(oi[i], r));
      for (int i = oi_in[v.first]; i < oi_out[v.first]; i++)
        dp[memo[oi[i]]] = max(dp[memo[oi[i]]], dep[oi[i]]);
    }
  if (!keep) {
    for (int i = oi_in[r]; i < oi_out[r]; i++) dp[memo[oi[i]]] = -1;
  }
}
int dfs_las(int r) {
  for (auto v : G[r]) ans[r] = max(ans[r], dfs_las(v.first));
  return ans[r];
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  for (int i = 0; i < (1 << 22); i++) dp[i] = -1;
  int n;
  cin >> n;
  oi.resize(n);
  for (int i = 2; i <= n; i++) {
    int y;
    char c;
    cin >> y >> c;
    G[y].push_back(make_pair(i, c - 'a'));
  }
  dfs_s(1);
  ve.push_back(0);
  for (int i = 0; i < 22; i++) ve.push_back(1 << i);
  dfs(1, true);
  dfs_las(1);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
