#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[";
  int i = 0;
  for (typename vector<T>::const_iterator it = p.begin(); it != p.end(); ++it) {
    os << (i == 0 ? "" : ", ") << *it;
    i++;
  }
  os << "]";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[";
  int i = 0;
  for (typename set<T>::const_iterator it = p.begin(); it != p.end(); ++it) {
    os << (i == 0 ? "" : ", ") << *it;
    i++;
  }
  os << "]";
  return os;
}
template <class K, class V>
ostream& operator<<(ostream& os, const map<K, V>& p) {
  os << "[";
  int i = 0;
  for (typename map<K, V>::const_iterator it = p.begin(); it != p.end(); ++it) {
    os << (i == 0 ? "" : ", ") << *it;
    i++;
  }
  os << "]";
  return os;
}
template <class T>
string toString(const T& o) {
  stringstream ss;
  ss << o;
  string ret;
  getline(ss, ret);
  return ret;
}
template <class T>
vector<T> subv(const vector<T>& v, int from, int to) {
  return vector<T>(v.begin() + min(max(0, from), (int)v.size()),
                   v.begin() + min(max(0, to), (int)v.size()));
}
pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator*(const int& a, const pair<int, int>& b) {
  return make_pair(a * b.first, a * b.second);
}
int n;
vector<vector<int> > g;
vector<long long> key, mn, mx;
vector<double> dp;
int root = -1;
void go(int v) {
  mn[v] = mx[v] = key[v];
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    go(to);
    mx[v] = max(mx[v], mx[to]);
    mn[v] = min(mn[v], mn[to]);
  }
}
void sum(int v, long long sm, int h) {
  if (h) dp[v] = sm / (1.0l * h);
  if (g[v].size()) {
    int l = g[v][0];
    int r = g[v][1];
    sum(l, sm + mn[r], h + 1);
    sum(r, sm + mx[l], h + 1);
  }
}
int main() {
  cin >> n;
  key.resize(n);
  mn.resize(n);
  mx.resize(n);
  g.resize(n);
  dp.resize(n);
  for (int i = 0; i < n; ++i) {
    long long p, k;
    cin >> p >> k;
    key[i] = k;
    if (p == -1)
      root = i;
    else
      g[p - 1].push_back(i);
  }
  for (int i = 0; i < n; ++i)
    if (g[i].size())
      if (key[g[i][0]] > key[g[i][1]]) swap(g[i][0], g[i][1]);
  go(root);
  sum(root, 0, 0);
  vector<pair<int, int> > keys(n);
  for (int i = 0; i < n; ++i) keys[i] = make_pair(key[i], i);
  sort(keys.begin(), keys.end());
  int k;
  cin >> k;
  cout.precision(9);
  for (int i = 0; i < k; ++i) {
    int f;
    cin >> f;
    int pos =
        lower_bound(keys.begin(), keys.end(), make_pair(f, 0)) - keys.begin();
    int ok = 0;
    for (int p = pos - 1; p <= pos && !ok; ++p)
      if (0 <= p && p < n) {
        int ind = keys[p].second;
        if (g[ind].size() == 0) {
          cout << fixed << dp[ind] << endl;
          ok = 1;
        }
      }
    assert(ok);
  }
  return 0;
}
