#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
const double PI = 3.1415926535897932384626433832795;
template <class T>
T min(T &a, T &b) {
  return (a < b) ? a : b;
}
template <class T>
T max(T &a, T &b) {
  return (a > b) ? a : b;
}
template <class T>
T sqr(T &a) {
  return a * a;
}
template <class T>
T abs(T &a) {
  return (a < 0) ? (-a) : a;
}
inline void read(int &x) { scanf("%d", &x); }
inline void readln(int &x) { scanf("%d\n", &x); }
inline void write(int x) { printf("%d", x); }
inline void writeln(int x) { printf("%d\n", x); }
inline void read(long long &x) { scanf("%lld", &x); }
inline void readln(long long &x) { scanf("%lld\n", &x); }
inline void write(long long x) { printf("%lld", x); }
inline void writeln(long long x) { printf("%lld\n", x); }
inline void read(double &x) { scanf("%lf", &x); }
inline void readln(double &x) { scanf("%lf\n", &x); }
inline void write(double x) { printf("%.15lf", x); }
inline void writeln(double x) { printf("%.15lf\n", x); }
inline void read(char *s) { scanf("%s", s); }
inline void readln(char *s) { scanf("%s\n", s); }
inline void write(char *s) { printf("%s", s); }
inline void writeln(char *s) { printf("%s\n", s); }
inline int readInt() {
  int x;
  read(x);
  return x;
}
inline long long readLong() {
  long long x;
  read(x);
  return x;
}
inline double readDouble() {
  double x;
  read(x);
  return x;
}
inline void showTime() {}
struct SegmentTree {
  int n;
  long long sum[4 * 100005];
  int cnt[4 * 100005];
  void init(int _n) { n = _n; }
  void inc(int ti, int tl, int tr, int l, int r, long long add) {
    if (tl == l && tr == r) {
      sum[ti] += add;
      cnt[ti]++;
      return;
    }
    int tm = (tl + tr) >> 1;
    if (r <= tm) {
      inc(2 * ti, tl, tm, l, r, add);
    } else if (tm < l) {
      inc(2 * ti + 1, tm + 1, tr, l, r, add);
    } else {
      inc(2 * ti, tl, tm, l, tm, add);
      inc(2 * ti + 1, tm + 1, tr, tm + 1, r, add);
    }
  }
  long long getSum(int ti, int tl, int tr, int pos, long long have) {
    have += sum[ti];
    if (tl == tr) {
      return have;
    }
    int tm = (tl + tr) >> 1;
    if (pos <= tm) {
      return getSum(2 * ti, tl, tm, pos, have);
    } else {
      return getSum(2 * ti + 1, tm + 1, tr, pos, have);
    }
  }
  int getCnt(int ti, int tl, int tr, int pos, int have) {
    have += cnt[ti];
    if (tl == tr) {
      return have;
    }
    int tm = (tl + tr) >> 1;
    if (pos <= tm) {
      return getCnt(2 * ti, tl, tm, pos, have);
    } else {
      return getCnt(2 * ti + 1, tm + 1, tr, pos, have);
    }
  }
};
int n, k;
int root;
int Left[100005];
int Right[100005];
bool leaf[100005];
pair<int, int> q[100005];
double ans[100005];
int key[100005];
int minKey[100005];
int maxKey[100005];
SegmentTree tree;
void initKeys(int x) {
  minKey[x] = key[x];
  maxKey[x] = key[x];
  if (leaf[x]) {
    return;
  }
  initKeys(Left[x]);
  initKeys(Right[x]);
  minKey[x] = minKey[Left[x]];
  maxKey[x] = maxKey[Right[x]];
}
void dfs(int x, int L, int R, bool err) {
  if (L > R) {
    return;
  }
  if (err) {
    if (q[R].first < minKey[x]) {
      tree.inc(1, 0, k - 1, L, R, minKey[x]);
    } else if (q[L].first > maxKey[x]) {
      tree.inc(1, 0, k - 1, L, R, maxKey[x]);
    } else {
      throw 0;
    }
    return;
  }
  if (leaf[x]) {
    return;
  }
  int M = L - 1;
  int l = L, r = R;
  while (l <= r) {
    int m = (l + r) >> 1;
    if (q[m].first > key[x]) {
      r = m - 1;
    } else {
      l = m + 1;
      M = m;
    }
  }
  dfs(Left[x], L, M, false);
  dfs(Right[x], M + 1, R, false);
  dfs(Left[x], M + 1, R, true);
  dfs(Right[x], L, M, true);
}
int main() {
  read(n);
  memset((leaf), (-1), sizeof(leaf));
  memset((Left), (-1), sizeof(Left));
  memset((Right), (-1), sizeof(Right));
  for (int i = 0; i < ((int)(n)); i++) {
    int p;
    read(p);
    read(key[i]);
    if (p != -1) {
      p--;
      leaf[p] = false;
      if (Left[p] == -1) {
        Left[p] = i;
      } else {
        Right[p] = i;
        if (key[Left[p]] > key[Right[p]]) {
          swap(Left[p], Right[p]);
        }
      }
    } else {
      root = i;
    }
  }
  read(k);
  for (int i = 0; i < ((int)(k)); i++) {
    read(q[i].first);
    q[i].second = i;
  }
  sort(q, q + k);
  initKeys(root);
  tree.init(k);
  dfs(root, 0, k - 1, false);
  for (int i = 0; i < ((int)(k)); i++) {
    long long sum = tree.getSum(1, 0, k - 1, i, 0);
    int cnt = tree.getCnt(1, 0, k - 1, i, 0);
    ans[q[i].second] = (double)sum / cnt;
  }
  for (int i = 0; i < ((int)(k)); i++) {
    writeln(ans[i]);
  }
}
