#include <bits/stdc++.h>
using namespace std;
long long n, k, root, parent[100005], lft[100005], rgt[100005], val[100005],
    minV[100005], maxV[100005], dpt[100005];
long long sum[100005], bst[100005];
set<pair<long long, long long> > v;
void dfs(int u, int d) {
  dpt[u] = d;
  bst[u] = u;
  if (lft[u] == -1)
    minV[u] = val[u];
  else {
    dfs(lft[u], d + 1);
    minV[u] = minV[lft[u]];
  }
  if (rgt[u] == -1)
    maxV[u] = val[u];
  else {
    dfs(rgt[u], d + 1);
    maxV[u] = maxV[rgt[u]];
  }
  if (rgt[u] != -1) bst[u] = bst[rgt[u]];
}
void dfs2(int u, long long s) {
  sum[u] = s;
  if (lft[u] != -1) dfs2(lft[u], s + minV[rgt[u]]);
  if (rgt[u] != -1) dfs2(rgt[u], s + maxV[lft[u]]);
}
int main() {
  cin >> n;
  for (int u = 0; u < n; u++) {
    cin >> parent[u] >> val[u];
    if (parent[u] != -1)
      parent[u]--;
    else
      root = u;
    minV[u] = val[u];
    maxV[u] = val[u];
    lft[u] = -1;
    rgt[u] = -1;
    sum[100005] = 0;
  }
  for (int u = 0; u < n; u++)
    if (parent[u] != -1) {
      if (val[u] > val[parent[u]])
        rgt[parent[u]] = u;
      else
        lft[parent[u]] = u;
    }
  dfs(root, 0);
  dfs2(root, 0);
  for (int u = 0; u < n; u++) v.insert(pair<long long, long long>(val[u], u));
  cin >> k;
  long long query, id;
  for (int i = 0; i < k; i++) {
    cin >> query;
    set<pair<long long, long long> >::iterator it =
        v.lower_bound(pair<long long, long long>(query, 0));
    if (it == v.end()) it--;
    id = it->second;
    if (lft[id] != -1) {
      id = bst[lft[id]];
    }
    cout << fixed << setprecision(10) << (long double)1.0 * sum[id] / dpt[id]
         << endl;
  }
  cin >> n;
  return 0;
}
