#include <bits/stdc++.h>
using namespace std;
struct Node {
  int l, r, key, fth;
  double e;
};
int n, root;
vector<int> id, keys;
vector<bool> is_l;
vector<Node> nodes;
void dfs(int dep, int now, double e) {
  if (is_l[now])
    nodes[now].e = e / dep;
  else {
    int l = lower_bound((keys).begin(), (keys).end(), nodes[now].key) -
            keys.begin();
    int lmax = keys[l - 1], rmin = keys[l + 1];
    dfs(dep + 1, nodes[now].l, e + rmin);
    dfs(dep + 1, nodes[now].r, e + lmax);
  }
}
void work() {
  dfs(0, root, 0.0);
  int tn;
  cin >> tn;
  while (tn--) {
    int k;
    cin >> k;
    int r = lower_bound((keys).begin(), (keys).end(), k) - keys.begin();
    if (!is_l[id[r]]) r--;
    int l = id[r];
    cout << setiosflags(ios::fixed) << setprecision(9);
    cout << nodes[l].e << endl;
  }
}
void myin() {
  cin >> n;
  id.assign(n, 0);
  keys.clear();
  is_l.assign(n, true);
  nodes.resize(n);
  for (int n_ = (n), i = 0; i < n_; ++i) {
    int p, k;
    cin >> p >> k;
    p--;
    keys.push_back(k);
    if (p == -2)
      root = i;
    else
      is_l[p] = false;
    nodes[i].key = k;
    nodes[i].fth = p;
  }
  sort((keys).begin(), (keys).end());
  for (int n_ = (n), i = 0; i < n_; ++i) {
    int l =
        lower_bound((keys).begin(), (keys).end(), nodes[i].key) - keys.begin();
    id[l] = i;
    if (i != root) {
      if (nodes[i].key < nodes[nodes[i].fth].key)
        nodes[nodes[i].fth].l = i;
      else
        nodes[nodes[i].fth].r = i;
    }
  }
  id.push_back(n);
  is_l.push_back(false);
}
int main(int argc, char *argv[]) {
  myin();
  work();
  return 0;
}
