#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, MOD = 1e9 + 7;
int seg[N << 2], lz[N << 2], dp[N], second[N], A[N], trie[N][26], n, k;
void shift(int id, int l, int r) {
  seg[id] += lz[id];
  assert(seg[id] >= 0);
  if (r - l > 1) lz[id << 1] += lz[id], lz[id << 1 | 1] += lz[id];
  lz[id] = 0;
}
void upd(int ql, int qr, int x, int id = 1, int l = 0, int r = n) {
  shift(id, l, r);
  if (qr <= l || r <= ql) return;
  if (ql <= l && r <= qr) {
    lz[id] += x;
    return shift(id, l, r);
  }
  int mid = (l + r) >> 1;
  upd(ql, qr, x, id << 1, l, mid);
  upd(ql, qr, x, id << 1 | 1, mid, r);
  seg[id] = min(seg[id << 1], seg[id << 1 | 1]);
}
int get(int ql, int qr, int id = 1, int l = 0, int r = n) {
  shift(id, l, r);
  if (qr <= l || r <= ql) return MOD;
  if (ql <= l && r <= qr) return seg[id];
  int mid = (l + r) >> 1;
  return min(get(ql, qr, id << 1, l, mid), get(ql, qr, id << 1 | 1, mid, r));
}
void DFS(int v, int h = 0) {
  upd(h, h + 1, dp[v]);
  if (second[v]) upd(0, h + 1, 1);
  for (int i = 0; i < 26; i++)
    if (trie[v][i]) {
      int u = trie[v][i];
      dp[u] = dp[v] + 1;
      if (second[u]) dp[u] = min(dp[u], get(0, h + 1) + 1);
      DFS(u, h + 1);
      upd(0, h + 1, second[u]);
      second[v] += second[u];
    }
  upd(0, h + 1, -second[v]);
  upd(h, h + 1, -dp[v]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int p;
    char c;
    scanf("%d %c\n", &p, &c);
    trie[p][c - 'a'] = i;
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &A[i]);
    second[A[i]] = 1;
  }
  DFS(0);
  for (int i = 1; i <= k; i++) printf("%d ", dp[A[i]]);
  return 0;
}
