#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int son[MAXN][2];
int val[MAXN][2];
int ti[MAXN];
int fa[MAXN];
int key[MAXN];
int n, m;
int root;
int leaf_val[MAXN], leaf_tot;
int lca_val[MAXN];
double ans[MAXN];
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &fa[i], &key[i]);
  memset(son, 0, sizeof(son));
  for (int i = 1; i <= n; ++i) {
    if (fa[i] == -1) {
      root = i;
      continue;
    }
    son[fa[i]][key[i] > key[fa[i]]] = i;
  }
}
void val_cal(int x, int path_tot) {
  if (!son[x][0] && !son[x][1]) {
    ti[x] = path_tot;
    val[x][0] = val[x][1] = key[x];
    return;
  }
  int path_add = (son[x][0] && son[x][1]);
  val[x][0] = val[x][1] = 0;
  if (son[x][0]) {
    val_cal(son[x][0], path_tot + path_add);
    val[x][0] = val[son[x][0]][0];
  }
  if (son[x][1]) {
    val_cal(son[x][1], path_tot + path_add);
    val[x][1] = val[son[x][1]][1];
  }
}
void ans_cal(int x, long long path_ans) {
  if (!son[x][0] && !son[x][1]) {
    leaf_val[leaf_tot] = key[x];
    ans[leaf_tot++] = (double)path_ans / ti[x];
    return;
  }
  for (int i = 0; i < 2; ++i)
    if (son[x][i]) ans_cal(son[x][i], path_ans + val[son[x][i ^ 1]][i]);
}
int renew(int x) {
  if (fa[x] != x) return fa[x] = renew(fa[x]);
  return x;
}
void lca_cal(int x, int &prex) {
  if (!son[x][0] && !son[x][1]) {
    if (prex == -1) {
      prex = x;
      leaf_tot++;
      return;
    }
    renew(prex);
    lca_val[leaf_tot++] = key[fa[prex]];
    prex = x;
    return;
  }
  for (int i = 0; i < 2; ++i)
    if (son[x][i]) {
      lca_cal(son[x][i], prex);
      fa[son[x][i]] = x;
    }
}
void solve() {
  val[0][0] = val[0][1] = 0;
  val_cal(root, 0);
  leaf_tot = 0;
  ans_cal(root, 0);
  leaf_tot = 0;
  int prex = -1;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  lca_cal(root, prex);
  scanf("%d", &m);
  for (int x, pos, i = 0; i < m; ++i) {
    scanf("%d", &x);
    pos = upper_bound(leaf_val, leaf_val + leaf_tot, x) - leaf_val;
    if (pos == leaf_tot || (0 < pos && x < lca_val[pos])) --pos;
    printf("%.9lf\n", ans[pos]);
  }
}
int main() {
  init();
  solve();
}
