#include <bits/stdc++.h>
using namespace std;
int n, p, ch[1000005][26], S[1000005], k, on, sz[1000005], sta[1000005],
    dfn[1000005], dfs_clock, dp[1000005], idx[1000005];
bool isS[1000005];
char s[2];
vector<int> in[1000005], out[1000005];
multiset<int> MS;
void dfs(int x) {
  sta[x] = on + 1;
  dp[x] = 1E9;
  dfn[++dfs_clock] = x;
  if (isS[x]) {
    idx[dfs_clock] = ++on;
    ++sz[x];
  }
  for (int j = 0; j < 26; j++)
    if (ch[x][j]) {
      dfs(ch[x][j]);
      sz[x] += sz[ch[x][j]];
    }
}
int main() {
  scanf("%d", &n);
  ++n;
  for (int i = 2; i <= n; i++) {
    scanf("%d%s", &p, s);
    ++p;
    ch[p][s[0] - 'a'] = i;
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &S[i]);
    isS[++S[i]] = true;
  }
  dfs(1);
  dp[1] = 0;
  for (int i = 1, u, l, r; i <= n; i++) {
    u = dfn[i];
    if (idx[i]) {
      for (const int &j : in[idx[i]]) MS.insert(j);
      for (const int &j : out[idx[i]]) MS.erase(MS.lower_bound(j));
      if (!MS.empty()) dp[u] = min(dp[u], *MS.begin() + idx[i]);
    }
    for (int j = 0; j < 26; j++)
      if (ch[u][j]) dp[ch[u][j]] = min(dp[u] + 1, dp[ch[u][j]]);
    l = sta[u], r = sta[u] + sz[u];
    in[max(idx[i] + 1, l)].push_back(dp[u] + 1 - l);
    out[r].push_back(dp[u] + 1 - l);
  }
  for (int i = 1; i <= k; i++) printf("%d ", dp[S[i]]);
  return 0;
}
