#include <bits/stdc++.h>
using namespace std;
int n, m, k[100010], ch[100010][2], R, p, K, mi[100010], ma[100010];
vector<int> v;
vector<double> w;
void f(int c) {
  if (ch[c][0] == -1) {
    mi[c] = ma[c] = k[c];
    return;
  }
  f(ch[c][0]);
  mi[c] = mi[ch[c][0]];
  v.push_back(k[c]);
  f(ch[c][1]);
  ma[c] = ma[ch[c][1]];
}
void g(int c, int d, double s) {
  if (ch[c][0] == -1) {
    w.push_back(s / d);
    return;
  }
  g(ch[c][0], d + 1, s + mi[ch[c][1]]);
  g(ch[c][1], d + 1, s + ma[ch[c][0]]);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) ch[i][0] = ch[i][1] = -1;
  for (int i = 0; i < n; i++) {
    cin >> p >> k[i];
    if (p == -1)
      R = i;
    else {
      p--;
      if (ch[p][0] > -1 && k[i] > k[ch[p][0]])
        ch[p][1] = i;
      else
        ch[p][1] = ch[p][0], ch[p][0] = i;
    }
  }
  f(R);
  g(R, 0, 0);
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> K;
    cout << setprecision(11)
         << w[lower_bound(v.begin(), v.end(), K) - v.begin()] << endl;
  }
}
