#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int n, k, p[N], a[N], b[N], dp[N][2], sz[N], o[N];
char val[N];
vector<int> adj[N], q;
void calcSize(int v) {
  int res = b[v];
  for (int w : adj[v]) {
    calcSize(w);
    res += sz[w];
  }
  sz[v] = res;
}
void calcOrder(int v) {
  int t = p[v], res = b[t];
  for (int w : adj[t]) {
    if (w == v) continue;
    if (val[w] < val[v]) res += sz[w];
  }
  o[v] = res;
}
int answer(int v, int s) {
  if (dp[v][s] != -1) return dp[v][s];
  if (v == 0) return s;
  int res = N;
  if (s) {
    res = min(res, answer(p[v], 1) + o[v]);
    res = min(res, answer(v, 0) + 1);
  } else {
    if (b[v]) res = min(res, answer(p[v], 1) + o[v]);
    res = min(res, answer(p[v], 0) + 1);
  }
  return dp[v][s] = res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int t;
    char j;
    cin >> t >> j;
    adj[t].push_back(i);
    val[i] = j;
    p[i] = t;
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    int j;
    cin >> j;
    q.push_back(j);
    b[j] = 1;
  }
  calcSize(0);
  for (int i = 1; i <= n; i++) calcOrder(i);
  memset(dp, -1, sizeof(dp));
  for (int i : q) {
    cout << answer(i, 0) << " ";
  }
  return 0;
}
