#include <bits/stdc++.h>
bool DEBUG = false;
using namespace std;
int n, k, val[100000], l[100000], r[100000], maxim[100000], minim[100000], a, b,
    root, c;
int lb, la;
int bound[100000];
double ans[100000];
void dfs(int p) {
  if (DEBUG) {
    cout << "p"
         << ": " << (p) << endl;
  };
  if (l[p] == -1) {
    maxim[p] = minim[p] = val[p];
    return;
  }
  dfs(l[p]);
  dfs(r[p]);
  maxim[p] = ((maxim[l[p]]) > (maxim[r[p]]) ? (maxim[l[p]]) : (maxim[r[p]]));
  minim[p] = ((minim[l[p]]) < (minim[l[p]]) ? (minim[l[p]]) : (minim[l[p]]));
}
void get(int pos, double value, int num) {
  if (l[pos] == -1) {
    ans[la++] = value / num;
    return;
  }
  get(l[pos], value + minim[r[pos]], num + 1);
  bound[lb++] = val[pos];
  get(r[pos], value + maxim[l[pos]], num + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) l[i] = -1;
  for (int i = 0; i < (n); ++i) {
    scanf("%d%d", &a, &val[i]);
    a--;
    if (a == -2)
      root = i;
    else if (l[a] == -1)
      l[a] = i;
    else
      r[a] = i;
  }
  for (int i = 0; i < (n); ++i)
    if (l[i] != -1 && val[l[i]] > val[r[i]]) swap(l[i], r[i]);
  if (DEBUG) {
    cout << "l"
         << ": ";
    for (int innercounter = 0; innercounter < (n); ++innercounter)
      cout << l[innercounter] << " ";
    cout << endl;
  };
  if (DEBUG) {
    cout << "r"
         << ": ";
    for (int innercounter = 0; innercounter < (n); ++innercounter)
      cout << r[innercounter] << " ";
    cout << endl;
  };
  dfs(root);
  if (DEBUG) {
    cout << "minim"
         << ": ";
    for (int innercounter = 0; innercounter < (n); ++innercounter)
      cout << minim[innercounter] << " ";
    cout << endl;
  };
  if (DEBUG) {
    cout << "maxim"
         << ": ";
    for (int innercounter = 0; innercounter < (n); ++innercounter)
      cout << maxim[innercounter] << " ";
    cout << endl;
  };
  bound[lb++] = -1000000000;
  get(root, 0, 0);
  bound[lb++] = 2000000000;
  scanf("%d", &k);
  for (int test = 0; test < (k); ++test) {
    scanf("%d", &a);
    int lef = 0;
    int rig = lb - 2;
    int ps;
    while (rig - lef > 1) {
      int mid = (lef + rig) / 2;
      if (bound[mid] < a && a < bound[mid + 1]) {
        lef = rig = mid;
        break;
      } else if (bound[mid] > a)
        rig = mid;
      else
        lef = mid;
    }
    if (bound[lef] < a && a < bound[lef + 1])
      ps = lef;
    else if (bound[lef + 1] < a && a < bound[lef + 2])
      ps = lef + 1;
    else if (bound[lef + 2] < a && a < bound[lef + 3])
      ps = lef + 2;
    printf("%.9lf\n", ans[ps]);
  }
  return 0;
}
