#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, degree[MAXN], m;
double mark[MAXN], dn[MAXN][3], dp[MAXN];
pair<int, int> ar[MAXN], node[MAXN];
bool leaf[MAXN];
void g(int p, int k) {
  dn[p][0] = dn[p][1] = mark[p];
  degree[p] = k;
  if (ar[p].first) {
    g(ar[p].first, k + 1);
    g(ar[p].second, k + 1);
    dn[p][0] = dn[ar[p].first][0];
    dn[p][1] = dn[ar[p].second][1];
  }
}
void f(int p) {
  dp[ar[p].first] = dp[p] + dn[ar[p].second][0];
  dp[ar[p].second] = dp[p] + dn[ar[p].first][1];
  leaf[p] = true;
  if (ar[p].first) {
    leaf[p] = false;
    f(ar[p].first);
    f(ar[p].second);
  }
}
int main() {
  int a, b, root;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    mark[i] = b;
    node[i] = pair<int, int>(b, i);
    if (a == -1)
      root = i;
    else if (!ar[a].first)
      ar[a].first = i;
    else
      ar[a].second = i;
  }
  for (int i = 1; i <= n; i++)
    if (ar[i].first && mark[ar[i].first] > mark[ar[i].second])
      swap(ar[i].first, ar[i].second);
  g(root, 0);
  f(root);
  sort(node + 1, node + n + 1);
  cin >> m;
  for (int i = 1, v; i <= m; i++) {
    cin >> v;
    int tmp = lower_bound(node + 1, node + n + 1, pair<int, int>(v, 0)) - node;
    if (leaf[node[tmp].second] == false || tmp == n + 1) tmp--;
    printf("%.20lf\n", dp[node[tmp].second] / degree[node[tmp].second]);
  }
  return 0;
}
