#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 1e5 + 500;
const int mod = 1e9 + 7;
const int inf = 1e9 + 500;
int lb[maxn];
int rb[maxn];
int par[maxn];
int key[maxn];
int minn[maxn];
int maxx[maxn];
long double ans[maxn];
long long summ[maxn];
deque<pair<int, int> > qu[maxn];
int cn = 0;
void dfs(int a, int b, int t) {
  int sz = qu[b].size();
  if (sz == 0) {
    return;
  }
  if (lb[a] == 0 && rb[a] == 0) {
    for (auto e : qu[b]) {
      ans[e.second] = summ[b] / (long double)t;
    }
    return;
  }
  int mid;
  for (int i = 0; i < sz; i++) {
    if (qu[b][i].first > key[a]) {
      mid = i;
      break;
    }
    if (qu[b][sz - i - 1].first < key[a]) {
      mid = sz - i;
      break;
    }
  }
  if (mid > sz / 2) {
    for (int i = mid; i < sz; i++) {
      qu[cn].push_back(qu[b][i]);
    }
    for (int i = mid; i < sz; i++) {
      qu[b].pop_back();
    }
    summ[cn] = maxx[lb[a]] + summ[b];
    summ[b] += minn[rb[a]];
    cn++;
    dfs(rb[a], cn - 1, t + 1);
    dfs(lb[a], b, t + 1);
  } else {
    for (int i = 0; i < mid; i++) {
      qu[cn].push_back(qu[b][i]);
    }
    for (int i = 0; i < mid; i++) {
      qu[b].pop_front();
    }
    summ[cn] = minn[rb[a]] + summ[b];
    summ[b] += maxx[lb[a]];
    cn++;
    dfs(lb[a], cn - 1, t + 1);
    dfs(rb[a], b, t + 1);
  }
}
void dfs_set(int a) {
  if (lb[a] == 0 && rb[a] == 0) {
    maxx[a] = key[a];
    minn[a] = key[a];
    return;
  }
  dfs_set(rb[a]);
  dfs_set(lb[a]);
  maxx[a] = max(maxx[lb[a]], maxx[rb[a]]);
  minn[a] = min(minn[lb[a]], minn[rb[a]]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  int rot;
  for (int i = 0; i < n; i++) {
    cin >> par[i] >> key[i];
    par[i]--;
  }
  for (int i = 0; i < n; i++) {
    if (par[i] == -2) {
      rot = i;
    } else {
      if (key[i] < key[par[i]]) {
        lb[par[i]] = i;
      } else {
        rb[par[i]] = i;
      }
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int key;
    cin >> key;
    qu[cn].push_back(make_pair(key, i));
  }
  sort(qu[cn].begin(), qu[cn].end());
  cn++;
  dfs_set(rot);
  dfs(rot, 0, 0);
  cout << fixed << setprecision(10);
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}
