#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
vector<int> v[100000];
int l[100000], r[100000];
int val[100000], prev239[100000];
pair<int, int> mas[100000];
long long lval[100000], rval[100000];
void go(int x) {
  if (((int)(v[x]).size()) == 0) {
    lval[x] = rval[x] = val[x];
    return;
  }
  go(l[x]);
  go(r[x]);
  lval[x] = lval[l[x]];
  rval[x] = rval[r[x]];
}
int root;
long long sum[100000], col[100000];
void go2(int x, int l, int r, long long csum, long long ccol) {
  if (!((int)(v[x]).size())) {
    for (int i = l; i < r; i++) {
      sum[mas[i].second] = csum;
      col[mas[i].second] = ccol;
    }
    return;
  }
  int cv = val[x];
  int c = lower_bound(mas + l, mas + r, make_pair(cv, 0)) - mas;
  if (c > l) go2(::l[x], l, c, csum + lval[::r[x]], ccol + 1);
  if (c < r) go2(::r[x], c, r, csum + rval[::l[x]], ccol + 1);
}
int main() {
  memset(l, -1, sizeof(l));
  memset(r, -1, sizeof(r));
  cin >> n;
  for (int i = 0; i < (n); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    if (a != -2) {
      prev239[i] = a;
      v[a].push_back(i);
    } else {
      prev239[i] = -1;
      root = i;
    }
    val[i] = b;
  }
  for (int i = 0; i < (n); i++)
    if (((int)(v[i]).size()) > 1) {
      int a = val[v[i][0]];
      int b = val[v[i][1]];
      if (a < b) {
        l[i] = v[i][0];
        r[i] = v[i][1];
      } else {
        r[i] = v[i][0];
        l[i] = v[i][1];
      }
    }
  int k;
  cin >> k;
  for (int i = 0; i < (k); i++) {
    int a;
    scanf("%d", &a);
    mas[i] = make_pair(a, i);
  }
  sort(mas, mas + k);
  go(root);
  go2(root, 0, k, 0, 0);
  for (int i = 0; i < (k); i++) {
    printf("%.10lf\n", sum[i] / (double)col[i]);
  }
  return 0;
}
