#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
namespace SALLY {
int n, k;
int nxt[N][26], star[N], dp[N], total_star[N], temp[N], s[N];
void Min(int &a, int b) { a = a < b ? a : b; }
void Go(int u) {
  total_star[u] = star[u];
  temp[u] += star[u];
  if (star[u]) Min(dp[u], temp[u]);
  Min(temp[u], dp[u] + star[u]);
  for (int i = 0; i < 26; ++i)
    if (nxt[u][i]) {
      int v = nxt[u][i];
      Min(dp[v], dp[u] + 1);
      Min(temp[v], temp[u]);
      Go(v);
      total_star[u] += total_star[v];
      temp[u] += total_star[v];
    }
}
void Slash() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int p;
    char c;
    cin >> p >> c;
    nxt[p][c - 'a'] = i;
  }
  cin >> k;
  for (int i = 0; i < k; ++i) {
    cin >> s[i];
    star[s[i]] = 1;
  }
  for (int i = 0; i <= n; ++i) dp[i] = temp[i] = 1e9;
  dp[0] = 0;
  Go(0);
  for (int i = 0; i < k; ++i) cout << dp[s[i]] << ' ';
  cout << '\n';
}
}  // namespace SALLY
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  while (test--) SALLY::Slash();
}
