#include <bits/stdc++.h>
using namespace std;
long long labs(long long a) { return a < 0 ? (-a) : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
template <typename T>
struct Point {
  T x, y;
  Point() {}
  Point(T xx, T yy) : x(xx), y(yy) {}
};
template <typename T>
bool operator<(const Point<T> &p1, const Point<T> &p2) {
  return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;
}
struct Node {
  long long key;
  long long l, r;
  Node() {
    l = -1;
    r = -1;
  }
  long long ll, lr;
};
vector<Node> v;
const char LEFT = 'l', RIGHT = 'r';
int SetError(long long i, char mode) {
  if (v[i].l == -1) {
    v[i].ll = v[i].lr = v[i].key;
    return v[i].key;
  }
  v[i].ll = SetError(v[i].l, LEFT);
  v[i].lr = SetError(v[i].r, RIGHT);
  if (mode == LEFT) {
    return v[i].ll;
  } else {
    return v[i].lr;
  }
}
vector<pair<long long, double> > res;
void Func(long long i, long long r, long long sum, long long cnt) {
  if (v[i].l == -1) {
    res.push_back(make_pair(r, (double)sum / cnt));
    return;
  }
  Func(v[i].l, v[i].key, sum + v[v[i].r].ll, cnt + 1);
  Func(v[i].r, r, sum + v[v[i].l].lr, cnt + 1);
}
int main() {
  long long n;
  cin >> n;
  v.resize(n);
  Node nod;
  long long root = -1;
  for (int(i) = 0; (i) < (n); (i)++) {
    long long p, k;
    cin >> p >> k;
    p--;
    if (p == -2) {
      root = i;
    } else {
      if (v[p].l == -1)
        v[p].l = i;
      else
        v[p].r = i;
    }
    v[i].key = k;
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    if (v[i].l != -1 && v[v[i].l].key > v[v[i].r].key) {
      swap(v[i].l, v[i].r);
    }
  }
  SetError(root, LEFT);
  Func(root, INT_MAX, 0, 0);
  sort((res).begin(), (res).end());
  long long k;
  cin >> k;
  long long key;
  for (int(i) = 0; (i) < (k); (i)++) {
    cin >> key;
    printf(
        "%.10f\n",
        lower_bound((res).begin(), (res).end(), make_pair(key, 0.0))->second);
  }
  return 0;
}
