#include <bits/stdc++.h>
using namespace std;
const int maxN = 100000 + 20;
vector<pair<int, int> > adj[maxN];
int n, k, a, root, h[maxN];
pair<int, int> key[maxN], l[maxN];
long double dp[maxN];
void dfs(int v, bool flag) {
  if ((int)adj[v].size() == 0) l[v].first = l[v].second = v;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int u = adj[v][i].second;
    h[u] = h[v] + 1;
    if (flag && !i)
      dp[u] += dp[v] + key[l[adj[v][1 - i].second].first].first;
    else if (flag)
      dp[u] += dp[v] + key[l[adj[v][1 - i].second].second].first;
    dfs(u, flag);
    if (l[v].first == -1) l[v].first = l[u].first;
    l[v].second = l[u].second;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int par;
    cin >> par >> key[i].first;
    key[i].second = i;
    if (par != -1)
      adj[par - 1].push_back(make_pair(key[i].first, i));
    else
      root = i;
  }
  for (int i = 0; i < n; i++) {
    if (adj[i].size() > 0) {
      if (adj[i][0] > adj[i][1]) swap(adj[i][0], adj[i][1]);
    }
    l[i].first = l[i].second = -1;
  }
  dfs(root, 0), dfs(root, 1);
  for (int i = 0; i < n; i++) {
    if (h[i] > 0) dp[i] = dp[i] / h[i];
  }
  cin >> k;
  sort(key, key + n);
  for (int i = 0; i < k; i++) {
    cin >> a;
    int x = lower_bound(key, key + n, make_pair(a, -1)) - key;
    int t1 = key[x].second, t2 = key[x - 1].second;
    if (x == n)
      cout << fixed << setprecision(9) << dp[t2] << endl;
    else if (!(int)adj[t1].size())
      cout << fixed << setprecision(9) << dp[t1] << endl;
    else
      cout << fixed << setprecision(9) << dp[l[adj[t1][0].second].second]
           << endl;
  }
  return 0;
}
