#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct node {
  int key, left, right;
} tree[maxn];
int root, n;
map<int, double> data;
set<int> al;
void solve(int x, long long tot, int depth) {
  if (!tree[x].left && !tree[x].right)
    data[tree[x].key] = tot / double(depth);
  else {
    if (tree[x].left)
      solve(tree[x].left, tot + (data.lower_bound(tree[x].key)->first),
            depth + 1);
    if (tree[x].right)
      solve(tree[x].right, tot + ((--data.lower_bound(tree[x].key))->first),
            depth + 1);
  }
}
void init() {
  data.clear();
  memset(tree, 0, sizeof(tree));
  scanf("%d", &n);
  int fa[maxn];
  for (int i = 1; i <= n; i++) scanf("%d%d", &fa[i], &tree[i].key);
  for (int i = 1; i <= n; i++) {
    if (fa[i] == -1)
      root = i;
    else if (tree[i].key < tree[fa[i]].key)
      tree[fa[i]].left = i;
    else
      tree[fa[i]].right = i;
  }
  for (int i = 1; i <= n; i++) {
    if (!tree[i].left && !tree[i].right) data[tree[i].key] = 0;
    al.insert(tree[i].key);
  }
}
void work() {
  int m;
  solve(root, 0, 0);
  scanf("%d", &m);
  while (m--) {
    int x;
    scanf("%d", &x);
    int t1 = data.lower_bound(x)->first, t2 = *al.lower_bound(x);
    printf("%.9lf\n", t1 == t2 ? data.lower_bound(x)->second
                               : (--data.lower_bound(x))->second);
  }
}
int main() {
  init();
  work();
  return 0;
}
