#include <bits/stdc++.h>
using namespace std;
struct _ {
  _() { ios_base::sync_with_stdio(0); }
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
  o << "(" << t.first << ", " << t.second << ")";
  return o;
}
template <class T>
string tostring(T first, int len = 0, char c = '0') {
  stringstream ss;
  ss << first;
  string r = ss.str();
  if (r.length() < len) r = string(len - r.length(), c) + r;
  return r;
}
template <class T>
void PV(T a, T b, int n = 0, int w = 0, string s = " ") {
  int c = 0;
  while (a != b) {
    cout << tostring(*a++, w, ' ');
    if (a != b && (n == 0 || ++c % n))
      cout << s;
    else
      cout << "\n";
    cout.flush();
  }
}
template <class T>
inline bool chmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool chmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
const long long linf = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int N = 111111;
int n;
vector<int> g[N];
int key[N];
int maxv[N];
int minv[N];
int lmax[N];
int rmin[N];
int depth[N];
int father[N];
void dfs(int u, int par = -1) {
  father[u] = par;
  maxv[u] = key[u];
  minv[u] = key[u];
  if (par == -1)
    depth[u] = 0;
  else
    depth[u] = depth[par] + 1;
  if (g[u].size() == 0) return;
  for (int v : g[u]) {
    dfs(v, u);
    chmax(maxv[u], maxv[v]);
    chmin(minv[u], minv[v]);
  }
  lmax[u] = maxv[g[u][0]];
  rmin[u] = minv[g[u][1]];
}
int p[N][21];
void lca_init() {
  memset(p, -1, sizeof(p));
  ;
  for (int i = 0; i < n; i++) p[i][0] = father[i];
  for (int j = 1; 1 << j < n; j++)
    for (int i = 0; i < n; i++)
      if (p[i][j - 1] != -1) p[i][j] = p[p[i][j - 1]][j - 1];
}
int lca_up(int u, int m) {
  for (int i = 0; i <= 20; i++)
    if (m & (1 << i)) u = p[u][i];
  return u;
}
int lca(int a, int b) {
  if (depth[a] < depth[b]) swap(a, b);
  a = lca_up(a, depth[a] - depth[b]);
  if (a == b) return a;
  for (int i = 20; i >= 0; i--)
    if (p[a][i] != p[b][i]) a = p[a][i], b = p[b][i];
  return father[a];
}
double expect[N];
void dfs2(int u, double tot) {
  if (g[u].size() == 0) {
    expect[u] = tot / depth[u];
    return;
  }
  dfs2(g[u][0], tot + rmin[u]);
  dfs2(g[u][1], tot + lmax[u]);
}
int main() {
  cin >> n;
  int root = 0;
  for (int i = 0; i < n; i++) {
    int u, v;
    cin >> u >> v;
    if (u == -1) {
      root = i;
    } else {
      g[u - 1].push_back(i);
    }
    key[i] = v;
  }
  for (int i = 0; i < n; i++) {
    if (g[i].empty()) continue;
    if (key[g[i][0]] > key[g[i][1]]) swap(g[i][0], g[i][1]);
  }
  for (int i = 0; i < n; i++) lmax[i] = -inf, rmin[i] = inf;
  dfs(root);
  vector<pair<int, int> > leaf;
  for (int i = 0; i < n; i++)
    if (g[i].size() == 0) leaf.push_back(make_pair(key[i], i));
  sort((leaf).begin(), (leaf).end());
  lca_init();
  vector<pair<int, int> > interval;
  for (int i = 0; i < leaf.size(); i++) {
    if (i == 0) {
      interval.push_back(
          make_pair(-inf, key[lca(leaf[i].second, leaf[i + 1].second)] - 1));
    } else if (i + 1 == leaf.size()) {
      interval.push_back(
          make_pair(key[lca(leaf[i - 1].second, leaf[i].second)] + 1, inf));
    } else {
      interval.push_back(
          make_pair(key[lca(leaf[i - 1].second, leaf[i].second)] + 1,
                    key[lca(leaf[i].second, leaf[i + 1].second)] - 1));
    }
  }
  dfs2(root, 0);
  vector<double> res;
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int first;
    cin >> first;
    int id =
        lower_bound((interval).begin(), (interval).end(), make_pair(first, 0)) -
        interval.begin();
    if (id == interval.size() || first < interval[id].first) id--;
    res.push_back(expect[leaf[id].second]);
  }
  for (double i : res) cout << fixed << setprecision(12) << i << endl;
  return 0;
}
