#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
const int N = 100005;
int n, i, ojciec[N], wart[N], wys[N], w, bestleft[N], bestright[N], k, juz[N],
    a, root;
long long suma[N];
double ex[N];
vector<int> wek[N], val;
map<int, int> mapa;
queue<int> kol;
void jedz(int a) {
  int w = ojciec[a];
  if (wek[w][0] == a)
    suma[a] = suma[w] + bestleft[wek[w][1]];
  else
    suma[a] = suma[w] + bestright[wek[w][0]];
  wys[a] = wys[w] + 1;
  ex[a] = suma[a] * 1.0 / wys[a];
  if (wek[a].size() > 0) {
    jedz(wek[a][0]);
    jedz(wek[a][1]);
  }
}
int main() {
  scanf("%d", &n);
  val.push_back(INF);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &ojciec[i], &wart[i]);
    val.push_back(wart[i]);
    mapa[wart[i]] = i;
    ojciec[i]--;
    if (ojciec[i] != -2)
      wek[ojciec[i]].push_back(i);
    else
      root = i;
  }
  sort(val.begin(), val.end());
  for (i = 0; i < n; i++) {
    if (wek[i].size() == 0)
      kol.push(i);
    else if (wart[wek[i][0]] > wart[wek[i][1]])
      swap(wek[i][0], wek[i][1]);
  }
  while (kol.size() > 0) {
    w = kol.front();
    kol.pop();
    if (wek[w].size() == 0)
      bestleft[w] = bestright[w] = wart[w];
    else {
      bestleft[w] = bestleft[wek[w][0]];
      bestright[w] = bestright[wek[w][1]];
    }
    if (ojciec[w] != -2) {
      juz[ojciec[w]]++;
      if (juz[ojciec[w]] == 2) kol.push(ojciec[w]);
    }
  }
  jedz(wek[root][0]);
  jedz(wek[root][1]);
  scanf("%d", &k);
  while (k--) {
    scanf("%d", &a);
    w = lower_bound(val.begin(), val.end(), a) - val.begin();
    if (val[w] == INF || wek[mapa[val[w]]].size() == 2) w--;
    printf("%.10lf\n", ex[mapa[val[w]]]);
  }
  return 0;
}
