#include <bits/stdc++.h>
using namespace std;
struct {
  int v, next;
} edge[100005 * 2];
struct Tree {
  int l, r;
} tree[100005];
struct Node {
  int id, w;
} node[100005];
int head[100005], Left[100005], Right[100005], w[100005], step[100005];
long long sum[100005];
int n, k, num, root;
bool cmp(const Node& a, const Node& b) { return a.w < b.w; }
void addedge(int u, int v) {
  edge[num].v = v;
  edge[num].next = head[u];
  head[u] = num++;
}
void init() {
  int i, j;
  memset(head, -1, sizeof(head));
  num = 0;
  scanf("%d", &n);
  for (int k = 1; k <= n; k++) {
    scanf("%d%d", &i, &j);
    if (i == -1)
      root = k;
    else {
      addedge(i, k);
      addedge(k, i);
    }
    node[k].w = j;
    node[k].id = k;
  }
}
void dfs1(int x, int pre) {
  bool flag = false;
  for (int i = head[x]; i != -1; i = edge[i].next)
    if (edge[i].v != pre) {
      dfs1(edge[i].v, x);
      flag = true;
      if (node[x].w > node[edge[i].v].w) {
        Left[x] = Left[edge[i].v];
        tree[x].l = edge[i].v;
      } else {
        Right[x] = Right[edge[i].v];
        tree[x].r = edge[i].v;
      }
    }
  if (!flag) {
    tree[x].l = tree[x].r = -1;
    Left[x] = Right[x] = x;
  }
}
void dfs2(int x, long long Sum, int Step) {
  if (tree[x].l != -1) {
    dfs2(tree[x].l, Sum + node[Left[tree[x].r]].w, Step + 1);
    dfs2(tree[x].r, Sum + node[Right[tree[x].l]].w, Step + 1);
  } else {
    sum[x] = Sum;
    step[x] = Step;
  }
}
void solve() {
  int i, j;
  sort(node + 1, node + n + 1, cmp);
  for (i = 1; i <= n; i++) w[i] = node[i].w;
  w[n + 1] = (1 << 30);
  scanf("%d", &k);
  while (k--) {
    scanf("%d", &i);
    j = lower_bound(w + 1, w + 1 + n, i) - w;
    j = ((n) > (j) ? (j) : (n));
    if (tree[node[j].id].l != -1)
      j = Right[tree[node[j].id].l];
    else
      j = node[j].id;
    printf("%.10lf\n", sum[j] * 1.0 / step[j]);
  }
}
int main() {
  init();
  dfs1(root, -1);
  dfs2(root, 0, 0);
  solve();
  return 0;
}
