#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
int most[MAXN][2], s[MAXN][2], v[MAXN][2], key[MAXN], p[MAXN], N;
vector<pair<int, int> > nodes;
long long dp[MAXN], hei[MAXN];
bool is[MAXN];
void Find(int a) {
  most[a][0] = most[a][1] = s[a][0] = s[a][1] = a;
  for (__typeof(2) i = (0); i < (2); ++i) {
    int nei = v[a][i];
    if (nei != -1) {
      Find(nei);
      most[a][i] = most[nei][i];
      s[a][i] = most[nei][1 - i];
    }
  }
}
void dfs(int a, int h) {
  hei[a] = h;
  for (__typeof(2) i = (0); i < (2); ++i) {
    int nei = v[a][i];
    if (nei != -1) {
      dp[nei] = dp[a] + key[s[a][1 - i]];
      dfs(nei, h + 1);
    }
  }
}
int root;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (__typeof(N) i = (0); i < (N); ++i) {
    cin >> p[i] >> key[i];
    --p[i];
    nodes.push_back(pair<int, int>(key[i], i));
    v[i][0] = v[i][1] = -1;
  }
  for (__typeof(N) i = (0); i < (N); ++i) {
    if (p[i] >= 0)
      v[p[i]][(key[i] > key[p[i]])] = i;
    else
      root = i;
  }
  for (__typeof(N) i = (0); i < (N); ++i) is[i] = false;
  Find(root);
  for (__typeof(N) i = (0); i < (N); ++i) is[i] = false;
  dfs(root, 0);
  sort(nodes.begin(), nodes.end());
  int k;
  cin >> k;
  for (__typeof(k) i = (0); i < (k); ++i) {
    int a;
    cin >> a;
    int b = lower_bound(nodes.begin(), nodes.end(), pair<int, int>(a, 0)) -
            nodes.begin();
    if (b == ((int)(nodes).size())) --b;
    int t = nodes[b].second;
    int num = s[t][0];
    cout << fixed << setprecision(10) << (long double)dp[num] / hei[num]
         << endl;
  }
  return 0;
}
