#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  int id, key;
};
bool operator<(const node &a, const node &b) {
  if (a.key < b.key) return true;
  return false;
}
int x, y, i, j, k, root, n;
vector<int> a[100001];
int key[100001], l[100001], r[100001], pred[100001];
long double ans[100001];
node b[100001];
void get(int i) {
  if (a[i].size() == 0) {
    l[i] = i;
    r[i] = i;
    return;
  }
  get(a[i][0]);
  l[i] = l[a[i][0]];
  get(a[i][1]);
  r[i] = r[a[i][1]];
}
void solve(int i, long long sum, int col) {
  if (a[i].size() == 0) {
    ans[i] = (long double)sum / col;
    return;
  }
  solve(a[i][0], (long long)sum + key[l[a[i][1]]], col + 1);
  solve(a[i][1], (long long)sum + key[r[a[i][0]]], col + 1);
}
int get_l(int i) { return l[i]; }
long double find(int x) {
  int l = 1;
  int r = n;
  int k;
  int ver = 1;
  while (l <= r) {
    k = (l + r) / 2;
    if (b[k].key == x) {
      ver = b[k].id;
      if (a[ver].size() == 0) return ans[ver];
      ver = get_l(a[ver][1]);
      return ans[ver];
    }
    if (b[k].key > x)
      r = k - 1;
    else {
      l = k + 1;
      ver = k;
    }
  }
  ver = b[ver].id;
  if (a[ver].size() == 0) return ans[ver];
  ver = get_l(a[ver][1]);
  return ans[ver];
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x >> key[i];
    pred[i] = x;
    if (x != -1) {
      a[x].push_back(i);
    } else
      root = i;
  }
  for (i = 1; i <= n; i++)
    if (a[i].size() > 0) {
      if (key[a[i][0]] > key[a[i][1]]) swap(a[i][0], a[i][1]);
    }
  get(root);
  solve(root, 0, 0);
  for (i = 1; i <= n; i++) {
    b[i].id = i;
    b[i].key = key[i];
  }
  sort(b + 1, b + n + 1);
  cin >> k;
  cout.setf(ios ::fixed | ios ::showpoint);
  cout.precision(9);
  for (i = 1; i <= k; i++) {
    cin >> x;
    cout << find(x) << endl;
  }
  return 0;
}
