#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
const double pi = 3.1415926535897932384626433832795;
template <class T>
inline T Sqr(const T &x) {
  return x * x;
}
template <class T>
inline T Abs(const T &x) {
  return x >= 0 ? x : -x;
}
int n;
vector<int> ch[100005];
int mi[100005], ma[100005];
int key[100005];
vector<pair<int, double> > segs;
void calc_mm(int v) {
  if (ch[v].size() == 0) {
    mi[v] = ma[v] = key[v];
    return;
  }
  for (int i = 0; i < (ch[v].size()); i++) calc_mm(ch[v][i]);
  mi[v] = min(mi[ch[v][1]], mi[ch[v][0]]);
  ma[v] = max(ma[ch[v][1]], ma[ch[v][0]]);
}
int root;
void go(int v, int l, int r, int k, double x) {
  if (ch[v].empty()) {
    segs.push_back(make_pair(l, x / k));
    return;
  }
  int lc = ch[v][0];
  int rc = ch[v][1];
  if (key[lc] > key[rc]) swap(lc, rc);
  go(lc, l, key[v] - 1, k + 1, x + mi[rc]);
  go(rc, key[v] + 1, r, k + 1, x + ma[lc]);
}
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) {
    int p;
    scanf("%d%d", &p, &key[i]);
    if (p == -1)
      root = i;
    else
      ch[p - 1].push_back(i);
  }
  calc_mm(root);
  go(root, -1000, 1100000000, 0, 0);
  sort(segs.begin(), segs.end());
  int k;
  scanf("%d", &k);
  for (int i = 0; i < (k); i++) {
    int t;
    scanf("%d", &t);
    vector<pair<int, double> >::iterator it =
        lower_bound(segs.begin(), segs.end(), make_pair(t, 1e50));
    int idx = it - segs.begin() - 1;
    printf("%.10lf\n", segs[idx].second);
  }
}
int main() {
  solve();
  return 0;
}
