#include <bits/stdc++.h>
using namespace std;
int n, up[100111];
struct Vetka {
  int value;
  Vetka *left, *right;
  int level, mi, ma;
  double er;
};
Vetka tr[100111];
int lfc = 0, chc = 0;
pair<int, Vetka *> lf[100111];
pair<int, double> ch[100111];
void dfs(Vetka *v) {
  if (v->left) {
    dfs(v->left);
    v->mi = v->left->mi;
    dfs(v->right);
    v->ma = v->right->ma;
  } else {
    v->mi = v->ma = v->value;
  }
}
void dfs2(Vetka *v, int level, double er) {
  v->er = er;
  v->level = level;
  if (v->left) {
    dfs2(v->left, level + 1, er + v->right->mi);
    dfs2(v->right, level + 1, er + v->left->ma);
  }
}
int getSplit(Vetka *a, Vetka *b) {
  if (!a) return -9;
  while (a->level > b->level) a = tr + up[a - tr];
  while (a->level < b->level) b = tr + up[b - tr];
  while (a != b) {
    a = tr + up[a - tr];
    b = tr + up[b - tr];
  }
  return a->value;
}
int main() {
  Vetka *root;
  scanf("%d", &n);
  for (int v = 1; v <= n; v++) {
    scanf("%d%d", up + v, &tr[v].value);
    if (up[v] < 0) root = tr + v;
  }
  for (int v = 1; v <= n; v++) {
    int p = up[v];
    if (p > 0)
      if (tr[v].value < tr[p].value)
        tr[p].left = tr + v;
      else
        tr[p].right = tr + v;
  }
  dfs(root);
  dfs2(root, 0, 0.0);
  for (int v = 1; v <= n; v++)
    if (!tr[v].left) {
      lf[lfc++] = make_pair(tr[v].value, tr + v);
    }
  sort(lf, lf + lfc);
  Vetka *before = NULL;
  for (int i = 0; i < lfc; i++) {
    Vetka *a = lf[i].second;
    ch[chc++] = make_pair(getSplit(before, a), a->er / a->level);
    before = a;
  }
  int q, x;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &x);
    int a = 0, b = chc;
    while (a + 1 < b) {
      int c = (a + b) / 2, z = ch[c].first;
      if (z < x)
        a = c;
      else
        b = c;
    }
    printf("%.10lf\n", ch[a].second);
  }
}
