#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const long long inf = 1000000000;
struct snode {
  int val, lleft, rright, cs;
  int c[2];
} nodes[101010];
long long maxn = 2000000000;
map<long long, long long> s1, s2;
void add(map<long long, long long>& s, int i, long long a) {
  for (; i < maxn; i |= i + 1) s[i] += a;
}
long double sum(map<long long, long long>& s, int i) {
  long long res = 0;
  for (; i > 0; i &= i + 1, i--) res += s[i];
  return res;
}
void dfs(int s, long long left = 1, long long right = 2000000000) {
  if (nodes[s].cs == 0) {
    nodes[s].lleft = nodes[s].rright = nodes[s].val;
  } else {
    int& leftc = nodes[s].c[0];
    int& rightc = nodes[s].c[1];
    if (nodes[leftc].val > nodes[rightc].val) swap(leftc, rightc);
    dfs(leftc, left, nodes[s].val);
    dfs(rightc, nodes[s].val, right);
    nodes[s].lleft = nodes[leftc].lleft;
    nodes[s].rright = nodes[rightc].rright;
    add(s1, nodes[s].val, nodes[leftc].rright);
    add(s1, right, -nodes[leftc].rright);
    add(s2, nodes[s].val, 1);
    add(s2, right, -1);
    add(s1, left, nodes[rightc].lleft);
    add(s1, nodes[s].val, -nodes[rightc].lleft);
    add(s2, left, 1);
    add(s2, nodes[s].val, -1);
  }
}
int main(int argc, char** argv) {
  int n, ks;
  cin >> n;
  int root = 0;
  for (int i = 0; i < n; ++i) {
    int t, v;
    scanf("%d%d", &t, &v);
    t--;
    if (t != -2)
      nodes[t].c[nodes[t].cs++] = i;
    else
      root = i;
    nodes[i].val = v;
  }
  dfs(root);
  int x;
  cin >> ks;
  cout.setf(ios::fixed);
  cout.precision(10);
  for (int i = 0; i < ks; ++i) {
    scanf("%d", &x);
    cout << sum(s1, x) / sum(s2, x) << endl;
  }
  return (EXIT_SUCCESS);
}
