#include <bits/stdc++.h>
using namespace std;
int l[100005], r[100005], le[100005], ri[100005], first[100005], dep[100005],
    last, lca[100005];
double val[100005];
vector<pair<int, int> > g;
void build(int v, int p) {
  dep[v] = p;
  if (l[v] == 0) {
    le[v] = ri[v] = first[v];
    last = v;
    g.push_back(make_pair(first[v], v));
    return;
  }
  build(l[v], p + 1);
  lca[last] = v;
  build(r[v], p + 1);
  le[v] = le[l[v]];
  ri[v] = ri[r[v]];
}
void dfs(int v) {
  if (l[v] == 0) return;
  val[l[v]] += val[v] + le[r[v]];
  val[r[v]] += val[v] + ri[l[v]];
  dfs(l[v]);
  dfs(r[v]);
}
int main() {
  int n, m, i, p, k, root, v;
  while (~scanf("%d", &n)) {
    memset(l, 0, sizeof(l));
    memset(r, 0, sizeof(r));
    memset(lca, 0, sizeof(lca));
    memset(val, 0, sizeof(val));
    g.clear();
    for (i = 1; i <= n; i++) {
      scanf("%d%d", &p, &first[i]);
      if (p == -1)
        root = i;
      else if (l[p] == 0)
        l[p] = i;
      else
        r[p] = i;
    }
    for (i = 1; i <= n; i++)
      if (first[l[i]] > first[r[i]]) swap(l[i], r[i]);
    build(root, 0);
    dfs(root);
    scanf("%d", &m);
    while (m--) {
      scanf("%d", &k);
      if (g[g.size() - 1].first < k)
        v = g[g.size() - 1].second;
      else if (g[0].first > k)
        v = g[0].second;
      else {
        int i = lower_bound(g.begin(), g.end(), make_pair(k, 0)) - g.begin();
        int v1 = g[i - 1].second;
        int v2 = g[i].second;
        if (first[lca[v1]] > k)
          v = v1;
        else
          v = v2;
      }
      printf("%.10lf\n", val[v] / dep[v]);
    }
    printf("\n");
  }
  return 0;
}
