#include <bits/stdc++.h>
using namespace std;
template <class T>
void inline checkMax(T& a, T b) {
  if (a < b) a = b;
};
template <class T>
void inline checkMin(T& a, T b) {
  if (a > b) a = b;
};
int const N = 110000;
struct Node {
  int pnt, value, height, minv, maxv, id;
  long long sum;
  bool operator<(Node const& other) const { return value < other.value; }
} node[N + N];
int n;
vector<int> G[N];
void dfs1(int x, int h) {
  node[x].height = h;
  node[x].minv = node[x].maxv = node[x].value;
  for (__typeof__(G[x].begin()) _it = G[x].begin(); _it != G[x].end(); ++_it)
    for (int _once = 1, _done = 0; _once;
         (!_done) ? (_it = G[x].end(), --_it) : _it)
      for (__typeof__(*_it)& child = *_it; _once && !(_once = 0); _done = 1) {
        dfs1(child, h + 1);
        checkMin(node[x].minv, node[child].minv);
        checkMax(node[x].maxv, node[child].maxv);
      }
}
void dfs2(int x, long long sum) {
  node[x].sum = sum;
  if (((int)(G[x]).size())) {
    dfs2(G[x][0], sum + node[G[x][1]].minv);
    dfs2(G[x][1], sum + node[G[x][0]].maxv);
  }
}
bool cmp(int const& a, int const& b) { return node[a].value < node[b].value; }
int main() {
  while (scanf("%d", &n) == 1) {
    for (int n_ = (n), i = 0; i < n_; ++i) G[i].clear();
    int root = -1;
    for (int n_ = (n), i = 0; i < n_; ++i) {
      scanf("%d%d", &node[i].pnt, &node[i].value);
      node[i].pnt--;
      node[i].id = i;
      if (node[i].pnt >= 0)
        G[node[i].pnt].push_back(i);
      else
        root = i;
    }
    for (int n_ = (n), i = 0; i < n_; ++i) {
      sort((G[i]).begin(), (G[i]).end(), cmp);
    }
    dfs1(root, 0);
    dfs2(root, 0);
    int m;
    scanf("%d", &m);
    for (int n_ = (m), i = 0; i < n_; ++i) {
      scanf("%d", &node[i + n].value);
      node[i + n].id = i + n;
    }
    sort(node, node + n + m);
    int prev_leaf = -1;
    int next_leaf = -1;
    int leaf_pnt = -1;
    vector<double> ans(m);
    for (int n_ = (n + m), i = 0; i < n_; ++i) {
      if (i == 0) {
        next_leaf = 0;
        for (; next_leaf < n + m; ++next_leaf) {
          if (node[next_leaf].id < n && G[node[next_leaf].id].size() == 0) {
            break;
          }
        }
      }
      if (node[i].id >= n) {
        if (prev_leaf < 0) {
          ans[node[i].id - n] =
              node[next_leaf].sum / static_cast<double>(node[next_leaf].height);
        } else if (next_leaf >= n + m) {
          ans[node[i].id - n] =
              node[prev_leaf].sum / static_cast<double>(node[prev_leaf].height);
        } else {
          if (node[i].value < node[leaf_pnt].value) {
            ans[node[i].id - n] = node[prev_leaf].sum /
                                  static_cast<double>(node[prev_leaf].height);
          } else {
            ans[node[i].id - n] = node[next_leaf].sum /
                                  static_cast<double>(node[next_leaf].height);
          }
        }
      } else if (((int)(G[node[i].id]).size()) == 0) {
        leaf_pnt = i;
        prev_leaf = i;
        next_leaf = i + 1;
        for (; next_leaf < n + m; ++next_leaf) {
          if (node[next_leaf].id >= n) continue;
          if (G[node[next_leaf].id].size() == 0) {
            break;
          }
          if (node[leaf_pnt].height > node[next_leaf].height) {
            leaf_pnt = next_leaf;
          }
        }
      }
    }
    for (int n_ = (m), i = 0; i < n_; ++i) {
      printf("%.20f\n", ans[i]);
    }
  }
  return 0;
}
