#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 50;
int n, q, root;
int p[N];
int k[N];
int l[N];
int r[N];
int ll[N];
int rr[N];
int lr[N];
int rl[N];
int dt[N];
double sm[N];
int LL(int v) {
  int& res = ll[v];
  if (res != -1) return res;
  res = v;
  if (l[v] != -1) res = LL(l[v]);
  return res;
}
int RR(int v) {
  int& res = rr[v];
  if (res != -1) return res;
  res = v;
  if (r[v] != -1) res = RR(r[v]);
  return res;
}
int LR(int v) {
  int& res = lr[v];
  if (res != -1) return res;
  res = v;
  if (l[v] != -1) res = RR(l[v]);
  return res;
}
int RL(int v) {
  int& res = rl[v];
  if (res != -1) return res;
  res = v;
  if (r[v] != -1) res = LL(r[v]);
  return res;
}
int DT(int v) {
  int& res = dt[v];
  if (res != -1) return res;
  res = 0;
  if (p[v] != -2) res = 1 + DT(p[v]);
  return res;
}
double SM(int v) {
  double& res = sm[v];
  if (res != -1.0) return res;
  res = 0.0;
  if (p[v] != -2) {
    res = SM(p[v]);
    if (v == l[p[v]])
      res += k[RL(p[v])];
    else
      res += k[LR(p[v])];
  }
  return res;
}
vector<pair<int, int> > qq;
void Pre() {
  for (int i = 0; i < (int)(n); i++) qq.push_back(make_pair(k[i], i));
  sort((qq).begin(), (qq).end());
}
double Solve(int key) {
  vector<pair<int, int> >::iterator zz = upper_bound((qq).begin(), (qq).end(),
                                                     make_pair(key, 0)),
                                    yy = zz;
  if (zz == qq.end()) {
    zz--;
    yy--;
  } else if (zz != qq.begin())
    yy--;
  int v;
  if (DT(zz->second) < DT(yy->second))
    v = zz->second;
  else
    v = yy->second;
  if (key < k[v])
    v = LR(v);
  else
    v = RL(v);
  return (double)SM(v) / DT(v);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); i++) {
    scanf("%d %d", &p[i], &k[i]);
    p[i]--;
  }
  memset(l, -1, sizeof(l));
  memset(r, -1, sizeof(r));
  for (int i = 0; i < (int)(n); i++) {
    if (p[i] == -2)
      root = i;
    else {
      if (k[i] < k[p[i]])
        l[p[i]] = i;
      else
        r[p[i]] = i;
    }
  }
  memset(ll, -1, sizeof(ll));
  memset(rr, -1, sizeof(rr));
  memset(lr, -1, sizeof(lr));
  memset(rl, -1, sizeof(rl));
  memset(dt, -1, sizeof(dt));
  for (int i = 0; i < (int)(N); i++) sm[i] = -1.0;
  Pre();
  scanf("%d", &q);
  for (int i = 0; i < (int)(q); i++) {
    int key;
    scanf("%d", &key);
    printf("%.12lf\n", Solve(key));
  }
  return 0;
}
