#include <bits/stdc++.h>
using namespace std;
int n, m;
int k;
bool debug = false;
int node[100005], l[100005], r[100005], fa[100005], root;
vector<int> ns;
map<int, int> pos;
map<int, double> ans;
void dfs(int x, int deep, long long sum) {
  if (l[x] == 0) {
    ans[node[x]] = sum * 1.0 / deep;
    return;
  }
  int rightMin = ns[pos[node[x]] + 1], leftMax = ns[pos[node[x]] - 1];
  dfs(r[x], deep + 1, sum + leftMax);
  dfs(l[x], deep + 1, sum + rightMin);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", fa + i, node + i);
    ns.push_back(node[i]);
    if (fa[i] == -1) root = i;
  }
  for (int i = 1; i <= n; i++)
    if (fa[i] != -1) {
      if (node[fa[i]] > node[i]) {
        l[fa[i]] = i;
      } else
        r[fa[i]] = i;
    }
  sort(ns.begin(), ns.end());
  for (int i = 0; i < n; i++) pos[ns[i]] = i;
  dfs(root, 0, 0);
  scanf("%d", &k);
  while (k--) {
    scanf("%d", &m);
    auto it = upper_bound(ns.begin(), ns.end(), m);
    if (it == ns.end()) it--;
    double a = ans[*it];
    if (a < 1e-8) {
      it--;
      a = ans[*it];
    }
    printf("%.10lf\n", a);
  }
  return 0;
}
