#include <bits/stdc++.h>
using namespace std;
int n, root;
int val[100005];
int child[100005][2];
vector<pair<int, int> > query;
double ans[100005];
int minkey[100005], maxkey[100005];
void updateBounds(int node) {
  if (child[node][0] == -1) {
    minkey[node] = maxkey[node] = val[node];
    return;
  }
  updateBounds(child[node][0]);
  updateBounds(child[node][1]);
  minkey[node] = min(minkey[child[node][0]], minkey[child[node][1]]);
  maxkey[node] = max(maxkey[child[node][0]], maxkey[child[node][1]]);
}
void func(double sum, double num, int node, int lo, int hi) {
  int j;
  if (child[node][0] == -1) {
    for (j = lo; j < hi; j++) ans[query[j].second] = (sum * 1.0) / num;
    return;
  }
  int pos = upper_bound(query.begin() + lo, query.begin() + hi,
                        pair<int, int>(val[node], -1)) -
            query.begin();
  func(sum + minkey[child[node][1]], num + 1.0, child[node][0], lo, pos);
  func(sum + maxkey[child[node][0]], num + 1.0, child[node][1], pos, hi);
}
int main() {
  int i, j;
  cin >> n;
  memset(child, -1, sizeof(child));
  for (i = 0; i < n; i++) {
    int parent, value;
    cin >> parent >> value;
    val[i] = value;
    parent--;
    if (parent < 0) {
      root = i;
      continue;
    }
    if (child[parent][0] == -1)
      child[parent][0] = i;
    else
      child[parent][1] = i;
  }
  for (i = 0; i < n; i++)
    if (val[child[i][0]] > val[child[i][1]]) swap(child[i][0], child[i][1]);
  updateBounds(root);
  int q;
  cin >> q;
  for (j = 0; j < q; j++) {
    int qval;
    cin >> qval;
    query.push_back(pair<int, int>(qval, j));
  }
  sort(query.begin(), query.end());
  func(0.0, 0.0, root, 0, q);
  for (j = 0; j < q; j++) printf("%.9lf\n", ans[j]);
  return 0;
}
