#include <bits/stdc++.h>
using namespace std;
int n, k, x, t;
int key[200000 + 10], le[200000 + 10], ri[200000 + 10], rr[200000 + 10],
    ll[200000 + 10], h[200000 + 10], p[200000 + 10], a[200000 + 10];
long long sum[200000 + 10];
void precalc(int u, int dep = 0) {
  h[u] = dep;
  if (!le[u]) {
    rr[u] = ll[u] = key[u];
    a[t++] = u;
  } else {
    if (key[le[u]] > key[ri[u]]) swap(le[u], ri[u]);
    precalc(le[u], dep + 1);
    a[t++] = u;
    precalc(ri[u], dep + 1);
    ll[u] = ll[le[u]];
    rr[u] = rr[ri[u]];
  }
}
void dp(int u) {
  if (p[u] != -1)
    sum[u] = sum[p[u]] + (u == le[p[u]] ? ll[ri[p[u]]] : rr[le[p[u]]]);
  if (le[u]) dp(le[u]), dp(ri[u]);
}
int main() {
  scanf("%d", &n);
  int root;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i], &key[i]);
    if (p[i] == -1)
      root = i;
    else if (le[p[i]])
      ri[p[i]] = i;
    else
      le[p[i]] = i;
  }
  scanf("%d", &k);
  precalc(root);
  dp(root);
  for (int res, lo, hi, mi; k--;) {
    scanf("%d", &x);
    res = lo = 0;
    hi = t - 1;
    for (; lo < hi;) {
      mi = (lo + hi + 1) >> 1;
      if (key[a[mi]] > x)
        hi = mi - 1;
      else
        lo = mi;
    }
    lo += lo & 1;
    printf("%.12lf\n", (double)sum[a[lo]] / h[a[lo]]);
  }
  return 0;
}
