#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto& i : v) os << i << "\n";
  return os;
}
clock_t time_p = clock();
void timing() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
struct Node {
  Node()
      : left(-1),
        right(-1),
        v(0),
        p(-1),
        mini(0),
        maxi(2e9),
        minr(0),
        maxl(2e9),
        cnt(0),
        sum(0) {}
  int v;
  int left;
  int right;
  int p;
  int mini;
  int maxi;
  int minr;
  int maxl;
  int64_t cnt;
  int64_t sum;
  int depth;
};
int l;
vector<vector<int>> up;
vector<bool> vis;
void dfs3(vector<Node>& a, int u, int p, int steps) {
  a[u].depth = steps;
  up[u][0] = p;
  for (int i = 1; i <= l; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
  }
  if (a[u].left != -1) dfs3(a, a[u].left, u, steps + 1);
  if (a[u].right != -1) dfs3(a, a[u].right, u, steps + 1);
}
int get(int u, int x) {
  for (int i = l - 1; i >= 0; i--) {
    if (x & (1 << i)) u = up[u][i];
  }
  return u;
}
int lca(vector<Node>& a, int u, int v) {
  if (a[v].depth < a[u].depth) swap(u, v);
  int diff = a[v].depth - a[u].depth;
  for (int i = l - 1; i >= 0; i--) {
    if (diff & (1 << i)) v = up[v][i];
  }
  if (u == v) return u;
  for (int i = l - 1; i >= 0; i--) {
    if (up[u][i] != up[v][i]) {
      u = up[u][i];
      v = up[v][i];
    }
  }
  return up[u][0];
}
void dfs(vector<Node>& a, int u) {
  bool isLeaf = (a[u].left == -1);
  if (isLeaf) {
    a[u].maxi = a[u].v;
    a[u].mini = a[u].v;
  } else {
    dfs(a, a[u].left);
    dfs(a, a[u].right);
    a[u].maxi = max(a[a[u].left].maxi, a[a[u].right].maxi);
    a[u].mini = min(a[a[u].left].mini, a[a[u].right].mini);
    a[u].minr = a[a[u].right].mini;
    a[u].maxl = a[a[u].left].maxi;
  }
}
void dfs2(vector<Node>& a, int u) {
  bool isLeaf = (a[u].left == -1);
  if (isLeaf) return;
  a[a[u].left].cnt = a[u].cnt + 1;
  a[a[u].left].sum = a[u].sum + a[u].minr;
  a[a[u].right].cnt = a[u].cnt + 1;
  a[a[u].right].sum = a[u].sum + a[u].maxl;
  dfs2(a, a[u].left);
  dfs2(a, a[u].right);
}
int find(vector<Node>& a, int u, int v) {
  bool isLeaf = (a[u].left == -1);
  if (isLeaf) return u;
  if (v < a[u].v)
    return find(a, a[u].left, v);
  else
    return find(a, a[u].right, v);
}
void solve() {
  int n;
  cin >> n;
  vector<Node> a(n);
  int root = 0;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p >> a[i].v;
    p--;
    if (p >= 0) {
      a[i].p = p;
      if (a[p].left != -1) {
        if (a[i].v < a[a[p].left].v) {
          a[p].right = a[p].left;
          a[p].left = i;
        } else {
          a[p].right = i;
        }
      } else {
        a[p].left = i;
      }
    } else {
      root = i;
      a[i].p = i;
    }
  }
  vector<pair<int, int>> leafs;
  for (int i = 0; i < n; i++) {
    bool isLeaf = (a[i].left == -1);
    if (isLeaf) leafs.push_back({a[i].v, i});
  }
  sort(leafs.begin(), leafs.end());
  l = ceil(log2(n));
  up.assign(n, vector<int>(l + 1));
  vis.assign(n, false);
  dfs3(a, root, root, 0);
  dfs(a, root);
  dfs2(a, root);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int u;
    cin >> u;
    auto it = lower_bound(leafs.begin(), leafs.end(), make_pair(u, 0));
    int ind = it - leafs.begin();
    int index = 0;
    if (ind == 0)
      index = leafs[ind].second;
    else if (ind == leafs.size())
      index = leafs.back().second;
    else {
      int lc = lca(a, leafs[ind].second, leafs[ind - 1].second);
      if (a[lc].v > u)
        index = leafs[ind - 1].second;
      else
        index = leafs[ind].second;
    }
    cout << fixed << setprecision(15)
         << (long double)a[index].sum / a[index].cnt << "\n";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
