#include <bits/stdc++.h>
using namespace std;
long long n, k, root, sum[100010], cnt[100010], val[100010], lef[100010],
    righ[100010], maxv[100010], minv[100010];
vector<pair<long long, long long> > v;
inline void dfs(long long u) {
  maxv[u] = val[u];
  minv[u] = val[u];
  if (lef[u] != -1) {
    dfs(lef[u]);
    maxv[u] = max(maxv[u], maxv[lef[u]]);
    minv[u] = min(minv[u], minv[lef[u]]);
  }
  if (righ[u] != -1) {
    dfs(righ[u]);
    maxv[u] = max(maxv[u], maxv[righ[u]]);
    minv[u] = min(minv[u], minv[righ[u]]);
  }
}
inline void dfs2(long long u) {
  if (lef[u] == -1 && righ[u] == -1) {
    return;
  }
  sum[lef[u]] += (sum[u] + minv[righ[u]]);
  cnt[lef[u]] += cnt[u] + 1;
  dfs2(lef[u]);
  sum[righ[u]] += (sum[u] + maxv[lef[u]]);
  cnt[righ[u]] += cnt[u] + 1;
  dfs2(righ[u]);
}
signed main() {
  ios::sync_with_stdio(false);
  memset(lef, -1, sizeof(lef));
  memset(righ, -1, sizeof(righ));
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x, y;
    cin >> x >> y;
    val[i] = y;
    if (x == -1) {
      root = i;
    } else {
      if (lef[x] == -1)
        lef[x] = i;
      else if (val[lef[x]] > y) {
        righ[x] = lef[x];
        lef[x] = i;
      } else
        righ[x] = i;
    }
  }
  for (long long i = 1; i <= n; i++) v.push_back(make_pair(val[i], i));
  v.push_back(make_pair(1e9 + 7, 0));
  sort(v.begin(), v.end());
  dfs(root);
  dfs2(root);
  cin >> k;
  for (long long i = 1; i <= k; i++) {
    long long key;
    cin >> key;
    long long sum1, cnt1;
    long long pos =
        lower_bound(v.begin(), v.end(), make_pair(key, 0ll)) - v.begin();
    if (pos == v.size() - 1)
      sum1 = sum[v[v.size() - 2].second], cnt1 = cnt[v[v.size() - 2].second];
    else if (pos == 0)
      sum1 = sum[v[0].second], cnt1 = cnt[v[0].second];
    else {
      if (lef[v[pos].second] == -1) {
        sum1 = sum[v[pos].second], cnt1 = cnt[v[pos].second];
      } else {
        sum1 = sum[v[pos - 1].second], cnt1 = cnt[v[pos - 1].second];
      }
    }
    cout << fixed << setprecision(15) << sum1 * 1.0 / cnt1 << endl;
  }
  return 0;
}
