#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100000;
const int VMAX = 1000 * 1000 * 1000;
int key[NMAX + 2], lev[NMAX + 2], minim[NMAX + 2], maxim[NMAX + 2];
bool viz[NMAX + 2];
long long fails[NMAX + 2];
vector<int> G[NMAX + 2];
vector<pair<int, int> > leafs;
int N, Q;
void PRE(int nod, int x = 1, int y = VMAX) {
  viz[nod] = 1;
  bool leaf = 1;
  minim[nod] = maxim[nod] = key[nod];
  for (auto son : G[nod]) {
    if (viz[son]) continue;
    leaf = 0;
    lev[son] = lev[nod] + 1;
    int meh = key[nod] - 1;
    if (key[son] < key[nod])
      PRE(son, x, meh);
    else
      PRE(son, meh + 1, y);
    minim[nod] = min(minim[nod], minim[son]);
    maxim[nod] = max(maxim[nod], maxim[son]);
  }
  if (leaf) {
    leafs.push_back({x, nod});
  }
}
void DFS(int nod) {
  viz[nod] = 1;
  if (!G[nod].empty()) {
    int lef = G[nod][0], rig = G[nod][1];
    fails[lef] += fails[nod];
    fails[rig] += fails[nod];
    fails[lef] += 1LL * minim[rig];
    fails[rig] += 1LL * maxim[lef];
    DFS(lef);
    DFS(rig);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  int root = 1;
  for (int i = 1; i <= N; ++i) {
    int father, value;
    cin >> father >> value;
    if (father != -1) {
      G[father].push_back(i);
    } else
      root = i;
    key[i] = value;
  }
  for (int i = 1; i <= N; ++i) {
    if (!G[i].empty()) {
      if (key[G[i][0]] > key[G[i][1]]) swap(G[i][0], G[i][1]);
    }
  }
  memset(viz, 0, sizeof(viz));
  lev[root] = 1;
  PRE(root);
  memset(viz, 0, sizeof(viz));
  DFS(root);
  leafs.push_back({VMAX + 1, N + 1});
  cin >> Q;
  for (int i = 1; i <= Q; ++i) {
    int val;
    cin >> val;
    auto it = upper_bound(leafs.begin(), leafs.end(), make_pair(val, N + 2));
    --it;
    cout << fixed << setprecision(12)
         << (long double)1.0 * fails[it->second] / (lev[it->second] - 1)
         << '\n';
  }
  return 0;
}
