#include <bits/stdc++.h>
using namespace std;
const long long INF = 2000000000000000000LL;
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;
struct SegmentTree {
  int Tree[4 * 1000007], Lazy[4 * 1000007];
  SegmentTree() {}
  void pushdown(int at) {
    if (Lazy[at]) {
      Lazy[(at << 1)] += Lazy[at];
      Lazy[((at << 1) | 1)] += Lazy[at];
      Tree[(at << 1)] += Lazy[at];
      Tree[((at << 1) | 1)] += Lazy[at];
      Lazy[at] = 0;
    }
  }
  void build(int at, int l, int r) {
    Lazy[at] = 0;
    if (l == r) {
      Tree[at] = inf;
      return;
    }
    int mid = (l + r) / 2;
    build((at << 1), l, mid);
    build(((at << 1) | 1), mid + 1, r);
    Tree[at] = min(Tree[(at << 1)], Tree[((at << 1) | 1)]);
    Lazy[at] = 0;
  }
  void update(int at, int l, int r, int x, int y, int val) {
    if (x > r || y < l) return;
    if (x <= l && r <= y) {
      Tree[at] += val;
      Lazy[at] += val;
      return;
    }
    if (l != r) pushdown(at);
    int mid = (l + r) / 2;
    update((at << 1), l, mid, x, y, val);
    update(((at << 1) | 1), mid + 1, r, x, y, val);
    Tree[at] = min(Tree[(at << 1)], Tree[((at << 1) | 1)]);
  }
  void update2(int at, int l, int r, int pos, int val) {
    if (l == r) {
      Tree[at] = val;
      Lazy[at] = 0;
      return;
    }
    if (l != r) pushdown(at);
    int mid = (l + r) / 2;
    if (pos <= mid)
      update2((at << 1), l, mid, pos, val);
    else
      update2(((at << 1) | 1), mid + 1, r, pos, val);
    Tree[at] = min(Tree[(at << 1)], Tree[((at << 1) | 1)]);
  }
  int query(int at, int l, int r, int x, int y) {
    if (x > r || y < l) return inf;
    if (x <= l && r <= y) return Tree[at];
    if (l != r) pushdown(at);
    int mid = (l + r) / 2;
    return min(query((at << 1), l, mid, x, y),
               query(((at << 1) | 1), mid + 1, r, x, y));
  }
} seg;
const int N = 1e6 + 7;
vector<pair<int, int> > g[N];
bool mark[N];
int dp[N];
int n;
void prnt() {
  for (int i = 0; i <= n; ++i) {
    int val = seg.query(1, 0, n, i, i);
    cerr << (val >= inf ? "inf" : to_string(val)) << " ";
  }
  cerr << "\n";
}
int dfs(int u, int p, int sel) {
  int ret = mark[u];
  if (u > 0) {
    dp[u] = dp[p] + 1;
    seg.update(1, 0, n, 0, n, sel);
    if (mark[u]) dp[u] = min(dp[u], 1 + seg.query(1, 0, n, 0, n));
    seg.update2(1, 0, n, u, dp[u]);
  }
  for (auto qq : g[u])
    if (qq.second != p) {
      ret += dfs(qq.second, u, ret);
    }
  if (u > 0) {
    seg.update(1, 0, n, 0, n, -sel);
    seg.update2(1, 0, n, u, inf);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int p;
    char c;
    cin >> p >> c;
    g[p].push_back(pair<int, int>(c, i));
  }
  for (int i = 0; i <= n; ++i) {
    sort((g[i]).begin(), (g[i]).end());
  }
  int k;
  cin >> k;
  vector<int> resfor;
  for (int i = 1; i <= k; ++i) {
    int x;
    cin >> x;
    mark[x] = 1;
    resfor.push_back(x);
  }
  seg.build(1, 0, n);
  dp[0] = 0;
  seg.update2(1, 0, n, 0, 0);
  dfs(0, -1, 0);
  for (int x : resfor) cout << dp[x] << " ";
  cout << "\n";
  return 0;
}
