#include <bits/stdc++.h>
int t[1000005][26];
int total = 0;
int end[1000005], pos[1000005];
int vis[1000005];
int sum[1000005], depth[1000005], rank[1000005];
int s[1000005];
int a[1000005], b[1000005], f[1000005];
void build(int p, char c, int index) {
  int u = c - 'a';
  t[p][u] = ++total;
  end[total] = index;
  pos[index] = total;
}
void preWork(int p, int count) {
  sum[p] = vis[end[p]];
  rank[p] = count;
  count += sum[p];
  for (int i = 0; i < 26; i++) {
    if (t[p][i] != 0) {
      int v = t[p][i];
      depth[v] = depth[p] + 1;
      preWork(v, count);
      sum[p] += sum[v];
      count += sum[v];
    }
  }
}
int min(int a, int b) { return a > b ? b : a; }
void solve(int p, int minA, int minAdd) {
  minA = min(minA, a[p]);
  minAdd = min(minAdd, minA + b[p]);
  for (int i = 0; i < 26; i++) {
    if (t[p][i] != 0) {
      int v = t[p][i];
      f[v] = minA + depth[v];
      if (vis[end[v]]) f[v] = min(f[v], minAdd + rank[v] + 1);
      a[v] = f[v] - depth[v];
      b[v] = depth[v] - rank[v];
      solve(v, minA, minAdd);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  total = 1;
  pos[0] = total;
  vis[0] = 0;
  for (int i = 1; i <= n; i++) {
    int last;
    char c[2];
    scanf("%d%s", &last, c);
    build(pos[last], c[0], i);
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d", &s[i]);
    vis[s[i]] = 1;
  }
  preWork(1, 0);
  for (int i = 0; i < k; i++) {
  }
  f[1] = 0;
  a[1] = f[1] - depth[1];
  b[1] = depth[1] - rank[1];
  solve(1, 10000007, 10000007);
  for (int i = 0; i < k; i++) {
    printf("%d ", f[pos[s[i]]]);
  }
  printf("\n");
  return 0;
}
