#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int L[MAXN], R[MAXN], F[MAXN], val[MAXN];
int Min[MAXN], Max[MAXN];
double E[MAXN];
int deep[MAXN];
vector<int> vt;
inline bool isLeaf(int root) { return L[root] == 0 && R[root] == 0; }
void dfs(int root, int d) {
  deep[root] = d;
  E[root] = 0.0;
  if (isLeaf(root)) {
    Min[root] = Max[root] = val[root];
    return;
  }
  dfs(L[root], d + 1);
  dfs(R[root], d + 1);
  Min[root] = Min[L[root]];
  Max[root] = Max[R[root]];
}
void gao(int root) {
  if (F[root] != -1) {
    int p = F[root];
    if (val[root] < val[F[root]]) {
      E[root] = (E[p] * deep[p] + Min[R[p]]) / deep[root];
    } else {
      E[root] = (E[p] * deep[p] + Max[L[p]]) / deep[root];
    }
  }
  if (isLeaf(root)) {
    vt.push_back(root);
    return;
  }
  gao(L[root]);
  vt.push_back(root);
  gao(R[root]);
}
int main() {
  for (int n, m; ~scanf("%d", &n);) {
    int root, k;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &F[i], &val[i]);
    }
    for (int i = 1; i <= n; i++) {
      if (F[i] != -1) {
        if (val[i] < val[F[i]]) {
          L[F[i]] = i;
        } else {
          R[F[i]] = i;
        }
      } else {
        root = i;
      }
    }
    dfs(root, 0);
    vt.clear();
    gao(root);
    scanf("%d", &m);
    while (m--) {
      scanf("%d", &k);
      int left = 0, right = vt.size();
      while (left < right) {
        int mid = (left + right) >> 1;
        if (val[vt[mid]] > k)
          right = mid;
        else
          left = mid + 1;
      }
      if (right == vt.size() || !isLeaf(vt[right])) right--;
      printf("%.9f\n", E[vt[right]]);
    }
  }
  return 0;
}
