#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 110000;
int key[N_MAX];
vector<int> g[N_MAX];
int smin[N_MAX], smax[N_MAX];
bool ischild[N_MAX];
int all[N_MAX], allndx[N_MAX];
long double ans[N_MAX];
int cnt;
void dfs1(int v) {
  if (g[v].empty()) {
    smin[v] = smax[v] = key[v];
    all[cnt] = key[v], allndx[cnt] = v;
    ++cnt;
  } else {
    dfs1(g[v][0]);
    all[cnt] = key[v], allndx[cnt] = v;
    ++cnt;
    dfs1(g[v][1]);
    smin[v] = smin[g[v][0]];
    smax[v] = smax[g[v][1]];
  }
}
void dfs2(int v, int len, long long sum) {
  if (g[v].empty()) {
    ischild[v] = true;
    ans[v] = (long double)sum / len;
  } else {
    dfs2(g[v][0], len + 1, sum + smin[g[v][1]]);
    dfs2(g[v][1], len + 1, sum + smax[g[v][0]]);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int root = -1;
  for (int i = 0; i < n; ++i) {
    int p = 0;
    scanf("%d %d", &p, &key[i]);
    if (p == -1)
      root = i;
    else
      g[p - 1].push_back(i);
  }
  for (int i = 0; i < n; ++i)
    if (!g[i].empty())
      if (key[g[i][0]] > key[g[i][1]]) swap(g[i][0], g[i][1]);
  dfs1(root);
  dfs2(root, 0, 0L);
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    int r;
    scanf("%d", &r);
    int lb = lower_bound(all, all + cnt, r) - all;
    int tv;
    if (lb == n)
      tv = n - 1;
    else if (lb == 0)
      tv = 0;
    else if (ischild[allndx[lb - 1]])
      tv = lb - 1;
    else
      tv = lb;
    printf("%.10lf\n", (double)ans[allndx[tv]]);
  }
  return 0;
}
