#include <bits/stdc++.h>
using namespace std;
long long sum[100100];
long long cnt[100100];
pair<int, int> a[100100];
int val[100100];
int ri[100100];
int le[100100];
vector<vector<int> > g;
void dfs1(int v) {
  if (g[v].size() == 0) {
    ri[v] = le[v] = val[v];
    return;
  }
  dfs1(g[v][0]);
  dfs1(g[v][1]);
  le[v] = le[g[v][0]];
  ri[v] = ri[g[v][1]];
}
void dfs2(int v, int l, int r) {
  if (g[v].size() == 0) return;
  int V = val[v];
  int L = l, R = r;
  int best = -1;
  while (L <= R) {
    int m = (L + R) / 2;
    if (a[m].first > V) {
      best = m;
      R = m - 1;
    } else
      L = m + 1;
  }
  if (best == -1) {
    sum[l] += le[g[v][1]];
    sum[r + 1] -= le[g[v][1]];
    cnt[l]++;
    cnt[r + 1]--;
    dfs2(g[v][0], l, r);
  } else if (best == l) {
    sum[l] += ri[g[v][0]];
    sum[r + 1] -= ri[g[v][0]];
    cnt[l]++;
    cnt[r + 1]--;
    dfs2(g[v][1], l, r);
  } else {
    int l1 = l;
    int r1 = best - 1;
    int l2 = best;
    int r2 = r;
    sum[l1] += le[g[v][1]];
    sum[r1 + 1] -= le[g[v][1]];
    cnt[l1]++;
    cnt[r1 + 1]--;
    sum[l2] += ri[g[v][0]];
    sum[r2 + 1] -= ri[g[v][0]];
    cnt[l2]++;
    cnt[r2 + 1]--;
    dfs2(g[v][0], l1, r1);
    dfs2(g[v][1], l2, r2);
  }
}
double ans[100100];
int main() {
  int root = -1;
  int n;
  scanf("%d", &n);
  g.resize(n);
  for (int i = (0); i < (n); ++i) {
    int v1, v2;
    scanf("%d%d", &v1, &v2);
    if (v1 != -1)
      g[v1 - 1].push_back(i);
    else
      root = i;
    val[i] = v2;
  }
  int k;
  scanf("%d", &k);
  for (int i = (0); i < (k); ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a, a + k);
  for (int i = (0); i < (n); ++i)
    if (g[i].size()) {
      int v1 = val[g[i][0]];
      int v2 = val[g[i][1]];
      if (v1 > v2) swap(g[i][0], g[i][1]);
    }
  dfs1(root);
  dfs2(root, 0, k - 1);
  long long num = 0, den = 0;
  for (int i = (0); i < (k); ++i) {
    num += sum[i];
    den += cnt[i];
    ans[a[i].second] = num / (double)den;
  }
  for (int i = (0); i < (k); ++i) printf("%.15lf\n", ans[i]);
  return 0;
}
