#include <bits/stdc++.h>
using namespace std;
const int N = 1010101;
int n, fa[N], v[N], ls[N], rs[N], i, root, m;
int vls[N], vrs[N];
long long c[N][2];
double ans[N];
struct g {
  int v, id;
} q[N];
bool cmp(g a, g b) { return a.v < b.v; }
void cc(int x, int w, int typ) {
  while (x <= m) {
    c[x][typ] += w;
    x += (x & -x);
  }
}
long long sum(int x, int typ) {
  long long ans = 0;
  while (x) {
    ans += c[x][typ];
    x -= (x & -x);
  }
  return ans;
}
void gao(int x) {
  if (ls[x])
    gao(ls[x]), vls[x] = vls[ls[x]];
  else
    vls[x] = v[x];
  if (rs[x])
    gao(rs[x]), vrs[x] = vrs[rs[x]];
  else
    vrs[x] = v[x];
}
int ef(int l, int r, int x) {
  int m;
  while (l <= r) {
    m = (l + r) >> 1;
    if (q[m].v > x)
      r = m - 1;
    else
      l = m + 1;
  }
  return r;
}
void get(int l, int r, int x) {
  if (l > r) return;
  int m = ef(l, r, v[x]);
  if (ls[x]) {
    cc(l, 1, 0);
    cc(m + 1, -1, 0);
    cc(l, vls[rs[x]], 1);
    cc(m + 1, -vls[rs[x]], 1);
    get(l, m, ls[x]);
  }
  if (rs[x]) {
    cc(m + 1, 1, 0);
    cc(r + 1, -1, 0);
    cc(m + 1, vrs[ls[x]], 1);
    cc(r + 1, -vrs[ls[x]], 1);
    get(m + 1, r, rs[x]);
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d%d", &fa[i], &v[i]);
  for (i = 1; i <= n; i++)
    if (fa[i] == -1)
      root = i;
    else {
      if (v[i] < v[fa[i]])
        ls[fa[i]] = i;
      else
        rs[fa[i]] = i;
    }
  gao(root);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) scanf("%d", &q[i].v), q[i].id = i;
  sort(q + 1, q + 1 + m, cmp);
  get(1, m, root);
  for (i = 1; i <= m; i++) ans[q[i].id] = sum(i, 1) * 1.0 / sum(i, 0);
  for (i = 1; i <= m; i++) printf("%.15f\n", ans[i]);
}
