#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0, f = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ '0');
    ch = getchar();
  }
  return f ? x : -x;
}
const int N = 1e6 + 5;
int n, ch[N][26], k, dp[N], leaf[N], a[N];
char s[20];
int dfs(int u, int candidate) {
  int siz = 0;
  if (leaf[u]) {
    dp[u] = min(dp[u], candidate + 1);
    ++siz;
  }
  for (int i = (0), _ed = (25); i <= _ed; ++i) {
    int v = ch[u][i];
    if (!v) continue;
    dp[v] = dp[u] + 1;
    siz += dfs(v, min(candidate, dp[u]) + siz);
  }
  return siz;
}
int main() {
  n = read();
  for (int i = (1), _ed = (n); i <= _ed; ++i) {
    int p = read();
    scanf("%s", s);
    ch[p][s[0] - 'a'] = i;
  }
  k = read();
  for (int i = (1), _ed = (k); i <= _ed; ++i) leaf[a[i] = read()] = 1;
  dfs(0, 0);
  for (int i = (1), _ed = (k); i <= _ed; ++i)
    printf("%d%c", dp[a[i]], i == k ? '\n' : ' ');
  return 0;
}
