#include <bits/stdc++.h>
using namespace std;
struct node {
  int key, lef, rig, Max, Min, siz;
} a[100010];
long long sum;
int n, d[100010];
double r[100010];
vector<int> b;
void dfs(int u) {
  a[u].Max = a[u].Min = a[u].key;
  a[u].siz = 1;
  if (a[u].lef) {
    d[a[u].lef] = d[u] + 1;
    dfs(a[u].lef);
    a[u].siz += a[a[u].lef].siz;
    a[u].Max = max(a[u].Max, a[a[u].lef].Max);
    a[u].Min = min(a[u].Min, a[a[u].lef].Min);
    d[a[u].rig] = d[u] + 1;
    dfs(a[u].rig);
    a[u].siz += a[a[u].rig].siz;
    a[u].Max = max(a[u].Max, a[a[u].rig].Max);
    a[u].Min = min(a[u].Min, a[a[u].rig].Min);
  }
}
void dfs2(int u, int root) {
  if (a[u].lef) {
    sum += a[a[u].rig].Min;
    dfs2(a[u].lef, root);
    sum -= a[a[u].rig].Min;
    int vt = root + a[a[u].lef].siz;
    sum += a[a[u].lef].Max;
    dfs2(a[u].rig, vt + 1);
    sum -= a[a[u].lef].Max;
  } else {
    r[root] = 1.0 * sum / d[u];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  int root = 1;
  for (int i = (1); i <= (n); i++) {
    int p, key;
    cin >> p >> key;
    a[i].key = key;
    if (p != -1) {
      if (a[p].lef == 0)
        a[p].lef = i;
      else
        a[p].rig = i;
    } else
      root = i;
    b.push_back(key);
    r[i - 1] = -1;
  }
  for (int i = (1); i <= (n); i++)
    if (a[a[i].lef].key > a[a[i].rig].key) swap(a[i].lef, a[i].rig);
  sort((b).begin(), (b).end());
  dfs(root);
  dfs2(root, 0);
  int m;
  cin >> m;
  while (m--) {
    int u;
    cin >> u;
    int dau = 0, cuoi = n - 1, mid;
    while (dau <= cuoi) {
      mid = (dau + cuoi) >> 1;
      if (b[mid] > u)
        cuoi = mid - 1;
      else
        dau = mid + 1;
    }
    int L = dau - 1;
    int R = dau;
    if (R > n - 1) {
      cout << fixed << setprecision(9) << r[L] << "\n";
    } else if (L < 0) {
      cout << fixed << setprecision(9) << r[R] << "\n";
    } else {
      if (r[L] == -1)
        cout << fixed << setprecision(9) << r[R] << "\n";
      else
        cout << fixed << setprecision(9) << r[L] << "\n";
    }
  }
  return 0;
}
