#include <bits/stdc++.h>
using namespace std;
int G[100001][2];
int nH[100001];
int K[100001];
int L[100001];
int A[100001];
int cont;
int minimo[100001];
int maximo[100001];
long long ansLeaf[100001];
void dfs(int nod) {
  minimo[nod] = K[nod];
  maximo[nod] = K[nod];
  if (nH[nod] != 0) {
    dfs(G[nod][0]);
    dfs(G[nod][1]);
    minimo[nod] = min(minimo[nod], min(minimo[G[nod][0]], minimo[G[nod][1]]));
    maximo[nod] = max(maximo[nod], max(maximo[G[nod][0]], maximo[G[nod][1]]));
  }
}
void dfs(int nod, long long current, int nivel) {
  if (nH[nod] != 0) {
    dfs(G[nod][0], current + minimo[G[nod][1]], nivel + 1);
    A[cont] = K[nod];
    L[cont++] = nivel;
    dfs(G[nod][1], current + maximo[G[nod][0]], nivel + 1);
  } else {
    A[cont] = K[nod];
    ansLeaf[cont] = current;
    L[cont++] = nivel;
  }
}
double getAns(int key) {
  if (key < A[0]) {
    return (ansLeaf[0] * 1.0) / L[0];
  }
  if (key > A[cont - 1]) {
    return (ansLeaf[cont - 1] * 1.0) / L[cont - 1];
  }
  int left = 0;
  int right = cont - 1;
  while (left + 1 < right) {
    int m = (left + right) >> 1;
    if (A[m] >= key) {
      right = m;
    } else {
      left = m;
    }
  }
  int ans = right;
  if (A[left] > key) {
    ans = left;
  }
  if (ans & 1) {
    ans--;
  }
  return (ansLeaf[ans] * 1.0) / L[ans];
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    nH[i] = 0;
  }
  int root;
  for (int i = 1; i <= N; i++) {
    int u, key;
    scanf("%d %d\n", &u, &key);
    if (u != -1) {
      G[u][nH[u]++] = i;
    } else {
      root = i;
    }
    K[i] = key;
  }
  for (int i = 1; i <= N; i++) {
    if (nH[i] != 0) {
      if (K[G[i][0]] > K[G[i][1]]) {
        swap(G[i][0], G[i][1]);
      }
    }
  }
  cont = 0;
  dfs(root);
  dfs(root, 0, 0);
  int K;
  scanf("%d\n", &K);
  while (K--) {
    int key;
    scanf("%d\n", &key);
    printf("%.10f\n", getAns(key));
  }
  return 0;
}
