#include <bits/stdc++.h>
using namespace std;
long long int LEFT[100005], RIGHT[100005];
long long int maxi[100005], mini[100005];
long long int num[100005];
vector<long long int> E[100005];
vector<pair<long long int, double> > ans;
void make(long long int pos) {
  if (((long long int)E[pos].size())) {
    make(E[pos][0]);
    make(E[pos][1]);
    maxi[pos] = maxi[E[pos][1]];
    mini[pos] = mini[E[pos][0]];
    LEFT[pos] = maxi[E[pos][0]];
    RIGHT[pos] = mini[E[pos][1]];
  } else {
    mini[pos] = maxi[pos] = LEFT[pos] = RIGHT[pos] = num[pos];
  }
}
void dfs(long long int pos, long long int r, double sum, double depth) {
  if (((long long int)E[pos].size())) {
    dfs(E[pos][0], num[pos], RIGHT[pos] + sum, depth + 1);
    dfs(E[pos][1], r, LEFT[pos] + sum, depth + 1);
    return;
  }
  ans.push_back(make_pair(max(r, num[pos]), sum / depth));
}
int main() {
  long long int n, root;
  cin >> n;
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    long long int a, b;
    cin >> a >> num[i];
    if (a == -1)
      root = i;
    else
      E[a - 1].push_back(i);
  }
  for (long long int i = 0; i < ((long long int)(n)); i++)
    if (((long long int)E[i].size()) && num[E[i][1]] < num[E[i][0]])
      swap(E[i][0], E[i][1]);
  make(root);
  dfs(root, (1ll << (long long int)(60)), 0, 0);
  sort(ans.begin(), ans.end());
  cin >> n;
  for (long long int i = 0; i < ((long long int)(n)); i++) {
    long long int tmp;
    cin >> tmp;
    vector<pair<long long int, double> >::iterator it;
    it = lower_bound(ans.begin(), ans.end(), make_pair(tmp, 0.0));
    if (it == ans.end()) it--;
    printf("%0.20lf\n", it->second);
  }
}
