#include <bits/stdc++.h>
using namespace std;
int N;
int key[100010], p[100010], l[100010], r[100010];
int Q;
pair<int, int> query[100010];
double ans[100010];
set<int> s;
void dfs(int x, int depth, long long sum, int low, int high) {
  int i;
  if (l[x] == -1) {
    for (i = low; i < high; i++) ans[query[i].second] = (double)sum / depth;
    return;
  }
  int low2 = low - 1, high2 = high;
  while (high2 - low2 > 1) {
    int mid = (high2 + low2) / 2;
    if (query[mid].first > key[x])
      high2 = mid;
    else
      low2 = mid;
  }
  __typeof(s.begin()) itr = s.find(key[x]);
  itr--;
  int small = (*itr);
  itr++;
  itr++;
  int big = (*itr);
  dfs(l[x], depth + 1, sum + big, low, high2);
  dfs(r[x], depth + 1, sum + small, high2, high);
}
int main(void) {
  int i, root = -1;
  scanf("%d", &N);
  for ((i) = 0; (i) < (int)(N); (i)++) {
    scanf("%d%d", &p[i], &key[i]);
    if (p[i] == -1)
      root = i;
    else
      p[i]--;
  }
  scanf("%d", &Q);
  for ((i) = 0; (i) < (int)(Q); (i)++) scanf("%d", &query[i].first);
  for ((i) = 0; (i) < (int)(Q); (i)++) query[i].second = i;
  sort(query, query + Q);
  for ((i) = 0; (i) < (int)(N); (i)++) l[i] = r[i] = -1;
  for ((i) = 0; (i) < (int)(N); (i)++)
    if (i != root)
      if (key[i] < key[p[i]])
        l[p[i]] = i;
      else
        r[p[i]] = i;
  for ((i) = 0; (i) < (int)(N); (i)++) s.insert(key[i]);
  dfs(root, 0, 0, 0, Q);
  for ((i) = 0; (i) < (int)(Q); (i)++) printf("%.12f\n", ans[i]);
  return 0;
}
