#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int M = 55;
const int K = 200010;
const int LIT = 2500;
const int INF = 1 << 30;
const int dir[6][2] = {{2, 0}, {-2, 0}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};
int n, m, root, pla[N];
vector<int> edg[N], locate;
vector<double> res;
pair<int, int> num[N];
void addedge(int fa, int son, int key) {
  edg[fa].push_back(son);
  num[son] = make_pair(key, key);
}
pair<int, int> dfs1(int u) {
  for (int i = 0; i < edg[u].size(); i++) {
    int v = edg[u][i];
    pair<int, int> tmp = dfs1(v);
    if (!i)
      num[u].first = tmp.first;
    else
      num[u].second = tmp.second;
  }
  return num[u];
}
void dfs2(int u, long long tot, long long cnt) {
  if (edg[u].size()) {
    locate.push_back(pla[u]);
    for (int i = 0; i < edg[u].size(); i++) {
      int tmp, son;
      son = edg[u][!i];
      if (!i)
        tmp = num[son].first;
      else
        tmp = num[son].second;
      tot += tmp;
      cnt++;
      dfs2(edg[u][i], tot, cnt);
      tot -= tmp;
      cnt--;
    }
  } else
    res.push_back((double)tot / cnt);
}
void init() {
  locate.clear();
  res.clear();
  for (int i = 0; i <= n; i++) edg[i].clear(), num[i] = make_pair(0, 0);
  for (int i = 1; i <= n; i++) {
    int key, f;
    scanf("%d %d", &f, &key);
    pla[i] = key;
    if (f == -1)
      root = i;
    else
      addedge(f, i, key);
  }
  for (int i = 1; i <= n; i++) {
    if (edg[i].size()) {
      int l = num[edg[i][0]].first, r = num[edg[i][1]].second;
      if (l > r) swap(edg[i][0], edg[i][1]);
    }
  }
  dfs1(root);
  dfs2(root, 0, 0);
  sort(locate.begin(), locate.end());
}
void solve() {
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int q;
    scanf("%d", &q);
    int x = lower_bound(locate.begin(), locate.end(), q) - locate.begin();
    printf("%.10lf\n", res[x]);
  }
}
int main() {
  while (cin >> n) {
    init();
    solve();
  }
}
