#include <bits/stdc++.h>
using namespace std;
int n, lef[100010], rig[100010];
int fat[100010], key[100010], root;
bool isleaf[100010];
pair<int, int> a[100010];
double ans[100010];
int depth[100010];
int leftmost[100010], rightmost[100010];
long long int sum[100010];
void dfs(int v) {
  if (lef[v] == -1) {
    leftmost[v] = rightmost[v] = v;
  } else {
    dfs(lef[v]);
    dfs(rig[v]);
    leftmost[v] = leftmost[lef[v]];
    rightmost[v] = rightmost[rig[v]];
  }
}
void dfs2(int v) {
  if (lef[v] == -1) {
    ans[v] = (sum[v] + .0) / depth[v];
  } else {
    depth[lef[v]] = depth[v] + 1;
    sum[lef[v]] = sum[v] + key[leftmost[rig[v]]];
    dfs2(lef[v]);
    depth[rig[v]] = depth[v] + 1;
    sum[rig[v]] = sum[v] + key[rightmost[lef[v]]];
    dfs2(rig[v]);
  }
}
int main() {
  scanf("%d", &n);
  memset(lef, -1, sizeof(lef));
  memset(rig, -1, sizeof(rig));
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &fat[i], &key[i]);
    a[i] = make_pair(key[i], i);
    if (fat[i] == -1)
      root = i;
    else if (lef[fat[i]] == -1)
      lef[fat[i]] = i;
    else
      rig[fat[i]] = i;
  }
  sort(a + 1, a + (n + 1));
  for (int i = 1; i <= n; i++)
    if (lef[i] == -1)
      isleaf[i] = true;
    else if (key[lef[i]] > key[rig[i]])
      swap(lef[i], rig[i]);
  dfs(root);
  sum[root] = depth[root] = 0;
  dfs2(root);
  int m, x;
  for (scanf("%d", &m); m--;) {
    scanf("%d", &x);
    int p = lower_bound(a + 1, a + n + 1, make_pair(x, 0)) - a;
    printf("%.10lf\n", (p == 1 || p < n + 1 && isleaf[a[p].second])
                           ? ans[a[p].second]
                           : ans[a[p - 1].second]);
  }
  return 0;
}
