#include <bits/stdc++.h>
using namespace std;
const int mxn = 1000001, k = 26;
int n, m;
int a[mxn], b[mxn], it[mxn], first[mxn], dp[mxn];
int tr[mxn][k];
int dfs(int c) {
  int ret = it[c];
  for (int i = 0, x; i < k; i++)
    if (x = tr[c][i]) {
      it[x] = ret + b[x];
      dp[x] = dp[c] + 1;
      if (b[x]) dp[x] = min(dp[x], it[x] + min(0, first[c]));
      first[x] = min(first[c], dp[x] - it[x] + b[x]);
      ret = dfs(x);
    }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    char c;
    cin >> x >> c;
    tr[x][c - 'a'] = i;
  }
  cin >> m;
  for (int i = 0; i < m; i++) cin >> a[i], b[a[i]] = 1;
  dfs(0);
  cout << dp[a[0]];
  for (int i = 1; i < m; i++) cout << " " << dp[a[i]];
  cout << '\n';
  return 0;
}
