#include <bits/stdc++.h>
using namespace std;
int val[100005], Max[100005], Min[100005];
int n;
int lef[100005], rig[100005];
void dfs(int r) {
  if (lef[r] == 0) {
    Max[r] = Min[r] = val[r];
    return;
  }
  dfs(lef[r]);
  dfs(rig[r]);
  Max[r] = Max[rig[r]];
  Min[r] = Min[lef[r]];
}
long long sum[100005];
int dep[100005];
void dfs(int r, long long s, int d) {
  if (lef[r] == 0) {
    sum[r] = s;
    dep[r] = d;
    return;
  }
  dfs(lef[r], s + Min[rig[r]], d + 1);
  dfs(rig[r], s + Max[lef[r]], d + 1);
}
struct node {
  int id, v;
  friend bool operator<(node a, node b) { return a.v < b.v; }
} a[100005];
bool cmp(node a, int x) { return a.v < x; }
int main() {
  scanf("%d", &n);
  int x, y, root;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    a[i].v = y;
    a[i].id = i;
    val[i] = y;
    if (x == -1)
      root = i;
    else {
      if (lef[x] == 0) {
        lef[x] = i;
      } else {
        rig[x] = i;
        if (val[lef[x]] > val[rig[x]]) {
          swap(lef[x], rig[x]);
        }
      }
    }
  }
  sort(a + 1, a + 1 + n);
  dfs(root);
  dfs(root, 0, 0);
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &x);
    int t = lower_bound(a + 1, a + 1 + n, x, cmp) - a;
    if (t == n + 1) t--;
    t = a[t].id;
    while (lef[t]) {
      if (val[t] > x)
        t = lef[t];
      else
        t = rig[t];
    }
    printf("%.10lf\n", 1.0 * sum[t] / dep[t]);
  }
  return 0;
}
