#include <bits/stdc++.h>
using namespace std;
const long maxn = 100005;
const long inf = 1000000005;
struct elem {
  long max;
  long min;
};
struct elem2 {
  long left;
  long right;
  long number;
  long past;
};
bool operator<(elem2 first, elem2 second) {
  return (first.number < second.number);
}
double answer[maxn];
elem extr[maxn];
elem2 tree[maxn];
long q, n, t1, t2;
bool leaf[maxn];
long root;
long tmas[maxn][3];
void dfs(long v) {
  if (v == 0) return;
  if (leaf[v] == true) {
    extr[v].min = tree[v].number;
    extr[v].max = tree[v].number;
    return;
  }
  dfs(tree[v].left);
  dfs(tree[v].right);
  extr[v].min = min(extr[tree[v].left].min, extr[tree[v].right].min);
  extr[v].max = max(extr[tree[v].left].max, extr[tree[v].right].max);
}
void dfs2(long long sum, long amount, long v) {
  if (leaf[v] == true) {
    double tt = sum;
    answer[v] = tt / amount;
    return;
  }
  if (tree[v].left != 0) {
    if (tree[v].right != 0)
      dfs2(sum + (long long)extr[tree[v].right].min, amount + 1, tree[v].left);
    else
      dfs2(sum, amount, tree[v].left);
  }
  if (tree[v].right != 0) {
    if (tree[v].left != 0)
      dfs2(sum + (long long)extr[tree[v].left].max, amount + 1, tree[v].right);
    else
      dfs2(sum, amount, tree[v].right);
  }
}
void third_step() {
  double result;
  long k, key;
  sort(tree + 1, tree + n + 1);
  scanf("%ld", &k);
  for (long i = 1; i <= k; i++) {
    scanf("%ld", &key);
    long start = 1;
    long finish = n;
    while (finish > start) {
      long middle = (start + finish) / 2;
      if (tree[middle].number >= key)
        finish = middle;
      else
        start = middle + 1;
    }
    if (start == 1)
      result = answer[tree[start].past];
    else {
      if (leaf[tree[start].past] == true)
        result = answer[tree[start].past];
      else
        result = answer[tree[start - 1].past];
    }
    printf("%0.10lf\n", result);
  }
}
int main() {
  scanf("%ld", &n);
  for (q = 1; q <= n; q++) {
    tree[q].left = 0;
    tree[q].right = 0;
  }
  for (q = 1; q <= n; q++) {
    scanf("%ld%ld", &tmas[q][1], &tmas[q][2]);
  }
  for (q = 1; q <= n; q++) {
    t1 = tmas[q][1];
    t2 = tmas[q][2];
    tree[q].number = t2;
    if (t1 == -1)
      root = q;
    else {
      if (t2 > tmas[t1][2])
        tree[t1].right = q;
      else
        tree[t1].left = q;
    }
  }
  for (q = 1; q <= n; q++)
    if ((tree[q].left == 0) && (tree[q].right == 0))
      leaf[q] = true;
    else
      leaf[q] = false;
  extr[0].min = inf;
  extr[0].max = -1;
  dfs(root);
  dfs2(0, 0, root);
  for (q = 1; q <= n; q++) tree[q].past = q;
  third_step();
}
