#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
string filename = "test";
struct T {
  int v;
  int index;
  T *l, *r, *p;
};
vector<vector<int> > left_right;
vector<int> vals;
vector<T*> ptrs;
T* build(int index, T* p_n) {
  T* c_n = new T();
  ptrs[index] = c_n;
  c_n->index = index;
  c_n->v = vals[index];
  c_n->p = p_n;
  T *l_n = NULL, *r_n = NULL;
  if (left_right[index].size() != 0) {
    int l_i = left_right[index][0], r_i = left_right[index][1];
    if (vals[l_i] < vals[r_i]) {
      l_n = build(l_i, c_n);
      r_n = build(r_i, c_n);
    } else {
      l_n = build(r_i, c_n);
      r_n = build(l_i, c_n);
    }
  }
  c_n->l = l_n;
  c_n->r = r_n;
  return c_n;
}
vector<pair<int, int> > children;
T* lm[100010];
T* rm[100010];
T* go_lm(T* node) {
  int index = node->index;
  if (lm[index] != NULL) return lm[index];
  if (node->l == NULL) {
    lm[index] = node;
  } else {
    lm[index] = go_lm(node->l);
  }
  return lm[index];
}
T* go_rm(T* node) {
  int index = node->index;
  if (rm[index] != NULL) return rm[index];
  if (node->r == NULL) {
    rm[index] = node;
  } else {
    rm[index] = go_rm(node->r);
  }
  return rm[index];
}
double mem[100010][2];
bool us[100010][2];
long long sums[100010];
long long go_sums(int index) {
  if (sums[index] != -1) return sums[index];
  long long& ret = sums[index];
  ret = 0;
  T* node = ptrs[index];
  if (node->p != NULL) {
    ret += go_sums(node->p->index);
    if (node->p->r == node) {
      ret += go_rm(node->p->l)->v;
    } else {
      ret += go_lm(node->p->r)->v;
    }
  }
  return ret;
}
int deep[100010];
int go_deep(int index) {
  if (deep[index] != -1) return deep[index];
  int& ret = deep[index];
  ret = 0;
  T* node = ptrs[index];
  if (node->p != NULL) {
    ret = go_deep(node->p->index) + 1;
  }
  return ret;
}
double go(int index) {
  long long v_sums = go_sums(index);
  int v_deep = go_deep(index);
  return 1.0 * v_sums / v_deep;
}
T* parents[100010];
void update_parents(T* v) {
  if (v->l != NULL) {
    T* vc = go_rm(v->l);
    if (parents[vc->index] == 0) {
      parents[vc->index] = v;
    }
    update_parents(v->l);
    update_parents(v->r);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  left_right = vector<vector<int> >(n);
  vals = vector<int>(n);
  int par, val;
  int head_index;
  for (int _n(n), i(0); i < _n; i++) {
    scanf("%d %d", &par, &val);
    vals[i] = val;
    if (par == -1) {
      head_index = i;
    } else {
      --par;
      left_right[par].push_back(i);
    }
  }
  ptrs = vector<T*>(n);
  T* head_node = build(head_index, NULL);
  for (int _n(left_right.size()), i(0); i < _n; i++) {
    if (left_right[i].size() == 0) {
      children.push_back(pair<int, int>(vals[i], i));
    }
  }
  sort((children).begin(), (children).end());
  memset(lm, 0, sizeof(lm));
  memset(rm, 0, sizeof(rm));
  memset(sums, -1, sizeof(sums));
  memset(deep, -1, sizeof(deep));
  memset(parents, 0, sizeof(parents));
  update_parents(head_node);
  int k;
  scanf("%d", &k);
  for (int _n(k), i(0); i < _n; i++) {
    scanf("%d", &val);
    int index = -1;
    vector<pair<int, int> >::iterator lb = lower_bound(
        (children).begin(), (children).end(), pair<int, int>(val, 0));
    if (lb == children.end()) {
      index = children.size() - 1;
    } else if (lb == children.begin()) {
      index = 0;
    } else {
      int i1 = lb - children.begin();
      int i0 = i1 - 1;
      if (parents[children[i0].second]->v > val) {
        index = i0;
      } else {
        index = i1;
      }
    }
    printf("%.10lf\n", go(children[index].second));
  }
  return 0;
}
