#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
int n, k, root;
int p[N], v[N], l[N], r[N];
int h[N], vl[N], vr[N];
long long sum[N];
int u[N], q[N];
int ans[N];
bool comp(int x, int y) { return v[x] < v[y]; }
int Vl(int x) {
  if (l[x] == -1) return v[x];
  if (vl[x] != -1) return vl[x];
  return vl[x] = Vl(l[x]);
}
int Vr(int x) {
  if (r[x] == -1) return v[x];
  if (vr[x] != -1) return vr[x];
  return vr[x] = Vr(r[x]);
}
int main() {
  scanf("%d", &n);
  for (int i = (0), _b = (n); i < _b; ++i) {
    scanf("%d%d", &p[i], &v[i]);
    if (p[i] != -1) --p[i];
  }
  memset(l, -1, sizeof l);
  memset(r, -1, sizeof r);
  for (int i = (0), _b = (n); i < _b; ++i)
    if (p[i] != -1) {
      if (v[i] < v[p[i]])
        l[p[i]] = i;
      else
        r[p[i]] = i;
    } else
      root = i;
  for (int i = (0), _b = (n); i < _b; ++i) u[i] = i;
  sort(u, u + n, comp);
  memset(vl, -1, sizeof vl);
  memset(vr, -1, sizeof vr);
  int a = 0, b = 1;
  q[0] = root;
  h[root] = 0;
  sum[root] = 0;
  while (a < b) {
    int i = q[a++];
    if (l[i] != -1) {
      sum[l[i]] = sum[i] + Vl(r[i]);
      h[l[i]] = h[i] + 1;
      q[b++] = l[i];
      sum[r[i]] = sum[i] + Vr(l[i]);
      h[r[i]] = h[i] + 1;
      q[b++] = r[i];
    }
  }
  scanf("%d", &k);
  for (int i = (0), _b = (k); i < _b; ++i) {
    scanf("%d", &v[n]);
    int x = lower_bound(u, u + n, n, comp) - u;
    if (x < n && l[u[x]] == -1)
      printf("%.12lf\n", double(sum[u[x]]) / h[u[x]]);
    else
      printf("%.12lf\n", double(sum[u[x - 1]]) / h[u[x - 1]]);
  }
  return 0;
}
