#include <bits/stdc++.h>
using namespace std;
vector<int> a[101000];
int val[101000];
int n;
int m;
int l[101000];
int r[101000];
int root = -1;
pair<int, int> k[101000];
int dfs(int ver, int x) {
  if (a[ver].size() == 0) return val[ver];
  if (x == 0) {
    if (l[ver] != 0) return l[ver];
    l[ver] = min(dfs(a[ver][0], 0), dfs(a[ver][1], 0));
    return l[ver];
  } else {
    if (r[ver] != 0) return r[ver];
    r[ver] = max(dfs(a[ver][0], 1), dfs(a[ver][1], 1));
    return r[ver];
  }
}
int cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
double res[101000];
int fnd(int v, int left, int right) {
  int l = left;
  int r = right;
  while (r - l > 1) {
    int key = (l + r) / 2;
    if (k[key].first > v)
      r = key;
    else
      l = key;
  }
  if (k[r].first < v) return r;
  if (k[l].first < v) return l;
  return -1;
}
double ncur, mn;
void dfs(int ver, int left, int right, double cur, int depth) {
  if (a[ver].size() == 0) {
    for (int i = left; i <= right; i++) res[k[i].second] += cur;
    return;
  }
  if (left > right) return;
  int x = val[ver];
  int ind = fnd(x, left, right);
  if (ind != -1) {
    int x = a[ver][0], y = a[ver][1];
    if (val[x] > val[y]) swap(x, y);
    double mn = l[y];
    ncur = cur * depth / (depth + 1.0) + mn / (depth + 1.0);
    dfs(x, left, ind, ncur, depth + 1);
    mn = r[x];
    ncur = cur * depth / (depth + 1.0) + mn / (depth + 1.0);
    dfs(y, ind + 1, right, ncur, depth + 1);
  } else {
    int x = a[ver][0], y = a[ver][1];
    if (val[x] > val[y]) swap(x, y);
    mn = r[x];
    ncur = cur * depth / (depth + 1.0) + mn / (depth + 1.0);
    dfs(y, left, right, ncur, depth + 1);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d%d", &x, &val[i]);
    if (x == -1)
      root = i;
    else
      a[x].push_back(i);
  }
  l[root] = dfs(root, 0);
  r[root] = dfs(root, 1);
  for (int i = 1; i <= n; i++)
    if (l[i] == 0) l[i] = r[i] = val[i];
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int x;
    scanf("%d", &x);
    k[i] = make_pair(x, i);
  }
  sort(k, k + m);
  dfs(root, 0, m - 1, 0, 0);
  for (int i = 0; i < m; i++) printf("%.10lf\n", res[i]);
  return 0;
}
