#include <bits/stdc++.h>
using namespace std;
int n;
int par[100000];
int lef[100000], righ[100000];
long long val[100000];
int root;
long long small[100000], big[100000];
long long num[100000], sum[100000];
long long lb[100000], ub[100000];
void gen(int cur) {
  if (lef[cur] == -1) {
    small[cur] = big[cur] = val[cur];
    return;
  }
  gen(lef[cur]);
  gen(righ[cur]);
  small[cur] = small[lef[cur]];
  big[cur] = big[righ[cur]];
}
void gen2(int cur) {
  if (par[cur] == -1) {
    num[cur] = 0;
    sum[cur] = 0;
  } else {
    num[cur] = num[par[cur]];
    sum[cur] = sum[par[cur]];
    num[cur]++;
    if (cur == lef[par[cur]])
      sum[cur] += small[righ[par[cur]]];
    else
      sum[cur] += big[lef[par[cur]]];
  }
  if (lef[cur] == -1) return;
  gen2(lef[cur]);
  gen2(righ[cur]);
}
void gen3(int cur, long long a, long long b) {
  lb[cur] = a;
  ub[cur] = b;
  if (lef[cur] == -1) return;
  gen3(lef[cur], a, val[cur] - 1);
  gen3(righ[cur], val[cur] + 1, b);
}
int main() {
  memset(lef, -1, sizeof(lef));
  memset(righ, -1, sizeof(righ));
  scanf("%d", &n);
  int i;
  root = -1;
  for (i = 0; i < n; i++) {
    scanf("%d %I64d", &par[i], &val[i]);
    if (par[i] != -1)
      par[i]--;
    else
      root = i;
  }
  for (i = 0; i < n; i++)
    if (par[i] != -1) {
      if (val[i] < val[par[i]])
        lef[par[i]] = i;
      else
        righ[par[i]] = i;
    }
  gen(root);
  gen2(root);
  gen3(root, -1000000000000LL, 1000000000000LL);
  vector<pair<long long, long long> > xx;
  for (i = 0; i < n; i++)
    if (lef[i] == -1) xx.push_back(make_pair(lb[i], i));
  sort(xx.begin(), xx.end());
  int nq;
  int q;
  scanf("%d", &nq);
  while (nq--) {
    scanf("%d", &q);
    pair<long long, long long> qq = make_pair(q, 1000000000000LL);
    int pos = upper_bound(xx.begin(), xx.end(), qq) - xx.begin() - 1;
    int xid = xx[pos].second;
    printf("%.10lf\n", (double)sum[xid] / num[xid]);
  }
  return 0;
}
