#include <bits/stdc++.h>
using namespace std;
const long long N = 100010;
long long n, a, b, k;
struct node {
  long long l, r, key;
} nd[N];
long long lr[N], rl[N], lm[N], rm[N], dep[N], val[N];
map<long long, long long> m;
void dfs1(long long x, long long d) {
  dep[x] = d;
  lr[x] = rl[x] = lm[x] = rm[x] = nd[x].key;
  if (nd[x].l) dfs1(nd[x].l, d + 1);
  if (nd[x].r)
    dfs1(nd[x].r, d + 1);
  else
    return;
  lr[x] = rm[nd[x].l];
  rl[x] = lm[nd[x].r];
  lm[x] = lm[nd[x].l];
  rm[x] = rm[nd[x].r];
}
void dfs2(long long x, long long sum) {
  val[x] = sum;
  if (nd[x].l) dfs2(nd[x].l, sum + rl[x]);
  if (nd[x].r) dfs2(nd[x].r, sum + lr[x]);
}
int main() {
  vector<long long> keys;
  scanf("%lld", &n);
  long long root = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", &a, &b);
    keys.push_back(b);
    nd[i].key = b;
    m[b] = i;
    if (a != -1) {
      if (nd[a].l == 0)
        nd[a].l = i;
      else
        nd[a].r = i;
    } else {
      root = i;
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (nd[nd[i].l].key > nd[nd[i].r].key) swap(nd[i].l, nd[i].r);
  }
  dfs1(root, 0);
  dfs2(root, 0);
  sort(keys.begin(), keys.end());
  scanf("%lld", &k);
  for (long long i = 1; i <= k; i++) {
    scanf("%lld", &a);
    auto itr = upper_bound(keys.begin(), keys.end(), a);
    if (itr == keys.end()) {
      --itr;
      printf("%.12lf\n", 1.0 * val[m[*itr]] / dep[m[*itr]]);
    } else if (itr == keys.begin()) {
      printf("%.12lf\n", 1.0 * val[m[*itr]] / dep[m[*itr]]);
    } else {
      auto itl = itr;
      itl--;
      auto iter = dep[m[*itr]] > dep[m[*itl]] ? itr : itl;
      printf("%.12lf\n", 1.0 * val[m[*iter]] / dep[m[*iter]]);
    }
  }
}
