#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0) {
    putchar('-'), write(-x);
  } else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const int N = 1e6 + 5;
int n, k, dfn, tg[N], ord[N], rk[N], ch[N][30], f[N], a[N], m;
multiset<int> s;
void dfs1(int x) {
  ord[x] = ++dfn;
  rk[dfn] = tg[x];
  for (int i = 0; i < 26; i++)
    if (ch[x][i]) dfs1(ch[x][i]);
}
void dfs2(int x, int fa) {
  if (x) f[x] = f[fa] + 1;
  if (tg[x]) f[x] = min(f[x], *s.begin() + rk[ord[x]]);
  int val = f[x];
  if (ord[x]) val -= rk[ord[x] - 1];
  s.insert(val);
  for (int i = 0; i < 26; i++)
    if (ch[x][i]) dfs2(ch[x][i], x);
  s.erase(s.find(val));
}
signed main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    int fa;
    read(fa);
    char cc = getchar();
    while (cc < 'a' || cc > 'z') cc = getchar();
    ch[fa][cc - 'a'] = i;
  }
  read(m);
  for (int i = 1; i <= m; i++) tg[read(a[i])] = 1;
  dfn = -1;
  dfs1(0);
  for (int i = 1; i <= n; i++) rk[i] += rk[i - 1];
  dfs2(0, -1);
  for (int i = 1; i <= m; i++) write(f[a[i]]), putchar(' ');
}
