#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k, node, ed[N], p[N], g[N][30], st[N], it, x[N], ans[N], s[N];
char a[N];
void dfs(int u) {
  st[u] = ++it;
  for (int i = 0; i < 26; ++i)
    if (g[u][i]) dfs(g[u][i]);
}
void dfs(int u, int l, int L) {
  if (s[st[u]] > s[st[u] - 1]) {
    l = min(l, L + s[st[u]]);
    ans[u] = l;
  }
  for (int i = 0; i < 26; ++i) {
    if (g[u][i]) {
      dfs(g[u][i], l + 1, min(L, l - s[st[u] - 1]));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  node = 1;
  ed[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i] >> a[i];
    ed[i] = ++node;
    g[ed[p[i]]][a[i] - 'a'] = node;
  }
  dfs(1);
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> x[i];
    s[st[ed[x[i]]]]++;
  }
  for (int i = 1; i <= node; ++i) s[i] += s[i - 1];
  dfs(1, 0, 0);
  for (int i = 1; i <= k; ++i) cout << ans[ed[x[i]]] << ' ';
}
