#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& a) {
  for (T& ai : a) is >> ai;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> const& a) {
  os << "[ ";
  for (const T& ai : a) os << ai << " ";
  return os << "]";
}
template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& a) {
  return is >> a.first >> a.second;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> const& a) {
  return os << "(" << a.first << ", " << a.second << ")";
}
class Solution {
 public:
  void parse() {
    int n;
    cin >> n;
    _c.resize(n + 1);
    for (int i = 1; i <= n; ++i) {
      int p;
      char c;
      cin >> p >> c;
      _c[p].emplace_back(c, i);
    }
    int k;
    cin >> k;
    _w.resize(k);
    cin >> _w;
    _d.resize(n + 1);
    _s.resize(n + 1);
    for (int wi : _w) _s[wi] = 1;
  }
  void solve() {
    dfs(0, 0);
    for (int wi : _w) cout << _d[wi] << " ";
  }

 private:
  int dfs(int u, int t) {
    int r = _s[u] ? 1 : 0;
    sort((_c[u]).begin(), (_c[u]).end());
    for (const auto& ci : _c[u]) {
      int v = ci.second;
      _d[v] = 1 + _d[u];
      if (_s[v]) _d[v] = min(_d[v], 1 + t + r);
      r += dfs(v, min(_d[v], t + r));
    }
    return r;
  }

 private:
  vector<vector<pair<char, int>>> _c;
  vector<int> _d, _w;
  vector<bool> _s;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  Solution soln;
  soln.parse();
  soln.solve();
  return 0;
}
