#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
int dfn1[N], dfn2[N], tot1, tot2;
int par[N], siz[N], key[N];
int g[N][26];
void dfs(int u) {
  dfn1[tot1++] = u;
  if (key[u])
    dfn2[u] = ++tot2;
  else
    dfn2[u] = tot2;
  siz[u] = 1;
  for (int i = 0; i < 26; i++)
    if (g[u][i]) {
      int v = g[u][i];
      par[v] = u;
      dfs(v);
      siz[u] += siz[v];
    }
}
int a[N], f[N];
vector<int> d[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int p;
    char c[2];
    scanf("%d%s", &p, c);
    g[p][c[0] - 'a'] = i;
  }
  int k;
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &a[i]);
    key[a[i]] = 1;
  }
  dfs(0);
  multiset<int> s;
  for (int i = 0; i <= n; i++) {
    int u = dfn1[i];
    if (i) f[u] = f[par[u]] + 1;
    for (int j : d[i]) s.erase(s.find(j));
    if (key[u]) f[u] = min(f[u], *s.begin() + dfn2[u]);
    int x = dfn2[u];
    if (key[u]) x--;
    s.insert(f[u] - x);
    d[i + siz[u]].push_back(f[u] - x);
  }
  for (int i = 1; i <= k; i++) printf("%d%c", f[a[i]], " \n"[i == k]);
}
