#include <bits/stdc++.h>
using namespace std;
struct node {
  int left;
  int right;
  int parent;
  int key;
  int l;
  int r;
  bool leaf;
};
vector<node> G;
vector<double> answ;
vector<int> leftb, an;
int n, k, t, root;
void dfs(int v) {
  if (G[v].leaf) {
    an.push_back(v);
    leftb.push_back(G[v].key);
    G[v].l = v;
    G[v].r = v;
    return;
  }
  dfs(G[v].left);
  an.push_back(G[G[v].left].r);
  leftb.push_back(G[v].key);
  dfs(G[v].right);
  G[v].l = G[G[v].left].l;
  G[v].r = G[G[v].right].r;
}
void dfs2(int v, double l = 0.0, double s = 0.0) {
  if (G[v].leaf) {
    answ[v] = s / l;
    return;
  }
  dfs2(G[v].right, l + 1.0, s + G[G[G[v].left].r].key);
  dfs2(G[v].left, l + 1.0, s + G[G[G[v].right].l].key);
}
int main() {
  scanf("%d", &n);
  G.resize(n);
  answ.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &G[i].parent, &G[i].key);
    G[i].leaf = true;
  }
  for (int i = 0; i < n; i++)
    if (G[i].parent == -1)
      root = i;
    else {
      G[i].parent--;
      G[G[i].parent].leaf = false;
      if (G[i].key > G[G[i].parent].key)
        G[G[i].parent].right = i;
      else
        G[G[i].parent].left = i;
    }
  leftb.push_back(-2000000000);
  dfs(root);
  dfs2(root);
  an.push_back(*an.rbegin());
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d", &t);
    int l = 0, r = leftb.size(), m;
    while (r - l > 1) {
      m = (r + l) / 2;
      if (leftb[m] > t)
        r = m;
      else
        l = m;
    }
    printf("%.9lf\n", answ[an[l]]);
  }
  return 0;
}
