#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
int P[1 << 17];
int L[1 << 17];
int R[1 << 17];
int A[1 << 17];
int Level[1 << 17];
int Left[1 << 17];
int Right[1 << 17];
double Res[1 << 17];
vector<pair<int, int> > V;
pair<int, int> dfs(int a) {
  if (L[a] == -1) return pair<int, int>(A[a], A[a]);
  Level[L[a]] = Level[a] + 1;
  Level[R[a]] = Level[a] + 1;
  pair<int, int> l = dfs(L[a]);
  pair<int, int> r = dfs(R[a]);
  Left[a] = l.second;
  Right[a] = r.first;
  return pair<int, int>(l.first, r.second);
}
void dfs(int a, int from, int to, long long sum) {
  if (L[a] == -1) {
    if (from <= to) {
      int p0 = lower_bound((V).begin(), (V).end(), pair<int, int>(from, -1)) -
               V.begin();
      int p1 = lower_bound((V).begin(), (V).end(),
                           pair<int, int>(to, int((V).size()))) -
               V.begin();
      int i;
      for (i = p0; i < p1; i++) Res[V[i].second] = (sum + 0.0) / Level[a];
    }
    return;
  }
  dfs(L[a], from, A[a] - 1, sum + Right[a]);
  dfs(R[a], A[a] + 1, to, sum + Left[a]);
}
int main() {
  int N;
  scanf("%d", &N);
  int i;
  for (i = 0; i < N; i++) {
    scanf("%d%d", &P[i], &A[i]);
    if (P[i] != -1) --P[i];
  }
  memset(L, -1, sizeof(L));
  memset(R, -1, sizeof(R));
  for (i = 0; i < N; i++)
    if (P[i] != -1) {
      if (A[i] < A[P[i]])
        L[P[i]] = i;
      else
        R[P[i]] = i;
    }
  int M;
  scanf("%d", &M);
  for (i = 0; i < M; i++) {
    int a;
    scanf("%d", &a);
    V.push_back(pair<int, int>(a, i));
  }
  sort((V).begin(), (V).end());
  for (i = 0; i < N; i++)
    if (P[i] == -1) {
      Level[i] = 0;
      dfs(i);
      dfs(i, -1, 1 << 30, 0);
    }
  for (i = 0; i < M; i++) printf("%.12lf\n", Res[i]);
  return 0;
};
