#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int inf = 1e9;
int n, x, p, k;
char s[2];
int idx[maxn], dp[maxn], ans[maxn], cnt[maxn];
vector<pair<int, int> > nex[maxn];
int tr[maxn << 2], f[maxn << 1];
void go(int now) {
  cnt[now] = idx[now] > 0;
  for (auto it : nex[now]) go(it.second);
  for (auto it : nex[now]) cnt[now] += cnt[it.second];
}
void dfs(int now, int val) {
  int tot = idx[now] > 0;
  if (idx[now]) {
    dp[now] = min(dp[now], val + 1);
    ans[idx[now]] = dp[now];
  }
  for (auto it : nex[now]) {
    dp[it.second] = min(dp[it.second], dp[now] + 1);
    dfs(it.second, min(val, dp[now]) + tot);
    tot += cnt[it.second];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %s", &p, s);
    x = s[0] - 'a' + 1;
    nex[p].push_back({x, i});
  }
  for (int i = 1; i <= n; i++) dp[i] = inf;
  for (int i = 0; i <= n; i++) sort(nex[i].begin(), nex[i].end());
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &x);
    idx[x] = i;
  }
  go(0);
  dfs(0, inf);
  for (int i = 1; i <= k; i++) printf("%d ", ans[i]);
  puts("");
  return 0;
}
