#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)2e18;
const string name = "c";
int const NMAX = 100500;
int n, zn[NMAX], root;
int l[NMAX], r[NMAX], znmin[NMAX], znmax[NMAX], lzn[NMAX], rzn[NMAX];
pair<int, int> q[NMAX];
double ans[NMAX];
void dfs(int v) {
  znmin[v] = znmax[v] = zn[v];
  if (l[v] == -1 || r[v] == -1) return;
  dfs(l[v]);
  dfs(r[v]);
  lzn[v] = znmax[l[v]];
  rzn[v] = znmin[r[v]];
  znmin[v] = min(znmin[v], min(znmin[l[v]], znmin[r[v]]));
  znmax[v] = max(znmax[v], max(znmax[l[v]], znmax[r[v]]));
}
void solve(int v, long long sum, int num, int ll, int rr) {
  if (ll > rr) return;
  if (l[v] == -1 || r[v] == -1) {
    for (int i = ll; i <= rr; ++i) ans[q[i].second] = (double)sum / num;
    return;
  }
  int pos = lower_bound(q + ll, q + rr + 1, make_pair(zn[v], 0)) - q;
  solve(l[v], sum + rzn[v], num + 1, ll, pos - 1);
  solve(r[v], sum + lzn[v], num + 1, pos, rr);
}
int main() {
  cin >> n;
  memset(l, 255, sizeof(l));
  memset(r, 255, sizeof(r));
  for (int i = 0; i < (int)n; i++) {
    int p;
    scanf("%d%d", &p, &zn[i]);
    p--;
    if (p < 0)
      root = i;
    else {
      if (l[p] == -1)
        l[p] = i;
      else {
        r[p] = i;
        if (zn[l[p]] > zn[r[p]]) swap(l[p], r[p]);
      }
    }
  }
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &q[i].first);
    q[i].second = i;
  }
  sort(q, q + n);
  dfs(root);
  solve(root, 0, 0, 0, n - 1);
  for (int i = 0; i < (int)n; i++) printf("%.10lf\n", ans[i]);
  return 0;
}
