#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e6 + 6;
int n, m, root = 0;
pair<int, char> g[mxn][26];
int siz[mxn];
int imp[mxn];
vector<int> qry;
int dp[mxn], par[mxn];
int id[mxn], mn[mxn];
inline bool cmp(pair<int, char> a, pair<int, char> b) {
  return a.second < b.second;
}
int dfn;
void dfs1(int x) {
  dfn += imp[x];
  id[x] = dfn;
  for (int y = 0; y < siz[x]; ++y) dfs1(g[x][y].first);
}
void dfs2(int x) {
  if (imp[x]) dp[x] = min(dp[x], mn[par[x]] + id[x]);
  dp[x] = min(dp[x], dp[par[x]] + 1);
  mn[x] = min(dp[x] - id[x] + imp[x], mn[par[x]]);
  for (int i = 0; i < siz[x]; ++i) dfs2(g[x][i].first);
}
inline void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    char c;
    cin >> x >> c;
    g[x][siz[x]++] = {i, c};
    par[i] = x;
  }
  for (int i = 0; i <= n; ++i) sort(g[i], g[i] + siz[i], cmp);
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    int x;
    cin >> x;
    imp[x] = 1;
    qry.push_back(x);
  }
  memset(dp, 63, sizeof(dp));
  memset(mn, 63, sizeof(mn));
  dp[root] = 0;
  dfs1(root);
  dfs2(root);
  for (int i = 0; i < qry.size(); ++i) cout << dp[qry[i]] << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int T = 1;
  for (; T--;) solve();
}
