#include <bits/stdc++.h>
using namespace std;
void file(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
template <typename Tp>
void read(Tp &x) {
  x = 0;
  long long fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= fh;
}
long long n, m;
long long fa[1000005], lson[1000005], rson[1000005], rt;
long long a[1000005];
struct Query {
  long long id, vl;
  bool operator<(Query b) const { return vl < b.vl; }
} q[1000005];
double ans[1000005];
struct node {
  long long nds, sm;
  double get_val() { return sm * 1.0 / nds; }
};
long long lft[1000005], rig[1000005];
void dfs1(long long x) {
  if (!lson[x]) {
    lft[x] = rig[x] = a[x];
    return;
  }
  dfs1(lson[x]);
  dfs1(rson[x]);
  lft[x] = lft[lson[x]];
  rig[x] = rig[rson[x]];
}
void dfs2(long long x, node tsm, long long L, long long R) {
  if (L > R) return;
  if (!lson[x]) {
    for (long long i = L; i <= R; ++i) {
      ans[q[i].id] = tsm.get_val();
    }
    return;
  }
  if (q[R].vl < a[x]) {
    dfs2(lson[x], (node){tsm.nds + 1, tsm.sm + lft[rson[x]]}, L, R);
    return;
  }
  if (q[L].vl > a[x]) {
    dfs2(rson[x], (node){tsm.nds + 1, tsm.sm + rig[lson[x]]}, L, R);
    return;
  }
  long long l = L, r = R, mid;
  while (l < r) {
    mid = ((l + r + 1) >> 1);
    if (q[mid].vl < a[x])
      l = mid;
    else
      r = mid - 1;
  }
  long long ps = l;
  dfs2(lson[x], (node){tsm.nds + 1, tsm.sm + lft[rson[x]]}, L, ps);
  dfs2(rson[x], (node){tsm.nds + 1, tsm.sm + rig[lson[x]]}, ps + 1, R);
}
signed main() {
  read(n);
  for (long long i = 1; i <= n; ++i) {
    read(fa[i]);
    read(a[i]);
    if (fa[i] == -1) rt = i;
  }
  for (long long i = 1; i <= n; ++i) {
    if (fa[i] == -1) continue;
    if (a[i] < a[fa[i]])
      lson[fa[i]] = i;
    else
      rson[fa[i]] = i;
  }
  dfs1(rt);
  read(m);
  for (long long i = 1; i <= m; ++i) {
    read(q[i].vl);
    q[i].id = i;
  }
  sort(q + 1, q + m + 1);
  dfs2(rt, (node){0, 0}, 1, m);
  for (long long i = 1; i <= m; ++i) printf("%.10lf\n", ans[i]);
  return 0;
}
