#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int val[N], mix[N], mx[N];
int c[N][2];
int pre[N];
int dep[N], depth[N];
void dfs1(int u, int dp) {
  depth[u] = dp;
  if (c[u][0]) {
    dfs1(c[u][0], dp + 1);
    dfs1(c[u][1], dp + 1);
    mix[u] = mix[c[u][0]];
    mx[u] = mx[c[u][1]];
  } else {
    mix[u] = mx[u] = val[u];
  }
}
long long sum[N];
int range[N], cnt;
void dfs2(int u, int x, int y, long long sx) {
  if (c[u][0]) {
    dfs2(c[u][0], x, val[u] - 1, sx + mix[c[u][1]]);
    dfs2(c[u][1], val[u] + 1, y, sx + mx[c[u][0]]);
  } else {
    sum[++cnt] = sx;
    range[cnt] = x;
    dep[cnt] = depth[u];
  }
}
int main() {
  int n, root;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &pre[i], &val[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (pre[i] == -1)
      root = i;
    else if (val[pre[i]] > val[i])
      c[pre[i]][0] = i;
    else
      c[pre[i]][1] = i;
  }
  dfs1(root, 0);
  dfs2(root, -0x7fffffff, 0x7fffffff, 0);
  int m, x;
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &x);
    int lt = 1, rt = cnt, mid, ans = -1;
    while (lt <= rt) {
      mid = (lt + rt) >> 1;
      if (range[mid] <= x)
        ans = mid, lt = mid + 1;
      else
        rt = mid - 1;
    }
    double ave = 1.0 * sum[ans] / dep[ans];
    printf("%.20lf\n", ave);
  }
  return 0;
}
