#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int lst = 1, nm[N], tr[N][26], dp[N], n, k, a[N], kol[N];
bool mrk[N];
void dfs(int v, int p, int st) {
  dp[v] = dp[p] + 1;
  if (mrk[v]) dp[v] = min(dp[v], st);
  kol[v] = mrk[v];
  for (int ch = 0; ch < 26; ch++)
    if (tr[v][ch]) {
      dfs(tr[v][ch], v, min(st, dp[v] + 1) + kol[v]);
      kol[v] += kol[tr[v][ch]];
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  nm[0] = lst;
  for (int i = 1; i <= n; i++) {
    int x;
    char c;
    cin >> x >> c;
    int cur = nm[x];
    int ch = c - 'a';
    assert(tr[cur][ch] == 0);
    tr[cur][ch] = ++lst;
    nm[i] = lst;
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> a[i];
    mrk[nm[a[i]]] = 1;
  }
  dp[0] = 0;
  for (int nt = 0; nt < 26; nt++)
    if (tr[1][nt] > 0) {
      dfs(tr[1][nt], 1, 1 + kol[1]);
      kol[1] += kol[tr[1][nt]];
    }
  for (int i = 0; i < k; i++) cout << dp[nm[a[i]]] << " ";
  return 0;
}
