#include <bits/stdc++.h>
using namespace std;
int p[111111], a[111111], l[111111], r[111111], n, H, q[111111], L, R,
    b[111111], m, d[111111], lm[111111], rm[111111], w[111111][17], k;
long long pm[111111];
inline bool cmp(int x, int y) { return a[x] < a[y]; }
int bs(int l, int r, int x) {
  while (l <= r) {
    int m = (l + r) / 2;
    if (a[b[m]] <= x)
      l = m + 1;
    else
      r = m - 1;
  }
  return l;
}
void goup(int& x, int y) {
  for (int k = 16; k >= 0; k--)
    if (y & (1 << k)) x = w[x][k];
}
int lca(int x, int y) {
  if (d[x] > d[y]) swap(x, y);
  goup(y, d[y] - d[x]);
  for (int k = 16; k >= 0; k--)
    if (w[x][k] != w[y][k]) x = w[x][k], y = w[y][k];
  return p[x];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", p + i, a + i);
  for (int i = 1; i <= n; i++)
    if (p[i] == -1) H = i;
  for (int i = 1; i <= n; i++)
    if (p[i] != -1)
      if (l[p[i]] != 0 && a[l[p[i]]] > a[i])
        r[p[i]] = l[p[i]], l[p[i]] = i;
      else if (l[p[i]] != 0)
        r[p[i]] = i;
      else
        l[p[i]] = i;
  L = 1;
  R = 1;
  q[1] = H;
  while (L <= R) {
    int x = q[L++];
    if (l[x] != 0) q[++R] = l[x];
    if (r[x] != 0) q[++R] = r[x];
  }
  for (int i = 2; i <= R; i++) {
    int x = q[i], y = p[x];
    w[x][0] = y;
    for (int k = 1; k <= 16; k++) w[x][k] = w[w[x][k - 1]][k - 1];
  }
  d[1] = 0;
  for (int i = 2; i <= R; i++) {
    int x = q[i];
    d[x] = d[p[x]] + 1;
  }
  for (int i = R; i >= 1; i--) {
    int x = q[i];
    if (l[x] == 0)
      lm[x] = a[x];
    else
      lm[x] = lm[l[x]];
    if (r[x] == 0)
      rm[x] = a[x];
    else
      rm[x] = rm[r[x]];
  }
  for (int i = 2; i <= R; i++) {
    int x = q[i];
    if (x == l[p[x]])
      pm[x] = pm[p[x]] + lm[r[p[x]]];
    else
      pm[x] = pm[p[x]] + rm[l[p[x]]];
  }
  for (int i = 1; i <= R; i++)
    if (l[q[i]] == 0 && r[q[i]] == 0) b[++m] = q[i];
  sort(b + 1, b + m + 1, cmp);
  scanf("%d", &k);
  while (k--) {
    int x;
    scanf("%d", &x);
    int p = bs(1, m, x);
    int ch;
    if (p == m + 1)
      ch = b[p - 1];
    else if (p == 1)
      ch = b[p];
    else {
      int g = lca(b[p - 1], b[p]);
      if (a[g] < x)
        ch = b[p];
      else
        ch = b[p - 1];
    }
    printf("%.9lf\n", (pm[ch] + 0.0) / (d[ch]));
  }
  return 0;
}
