#include <bits/stdc++.h>
using std::cin;
void dbg(const char *fmt, ...) {}
int k;
class node {
 public:
  node *left, *right;
  long long min, max;
  long long value;
  bool leaf;
  node() {
    left = right = 0;
    leaf = true;
  }
  void insert(node *c) {
    if (left == 0)
      left = c;
    else
      right = c;
    leaf = false;
  }
} tree[100000];
std::pair<int, int> ar[100000];
double ans[100000];
int pos = 0;
void build_tree(node *v) {
  if (v->leaf) {
    v->min = v->max = v->value;
  } else {
    if (v->left->value > v->right->value) std::swap(v->left, v->right);
    build_tree(v->left);
    build_tree(v->right);
    v->max = v->right->max;
    v->min = v->left->min;
  }
}
void solve(node *cur, long long min, long long max, long long sum, int count) {
  if (cur->leaf) {
    while (pos < k && ar[pos].first < max) {
      ans[ar[pos++].second] = (double)sum / ((double)count);
    }
  } else {
    solve(cur->left, min, cur->value, sum + cur->right->min, count + 1);
    solve(cur->right, cur->value, max, sum + cur->left->max, count + 1);
  }
}
int main() {
  node *root = 0;
  int n, p;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p >> tree[i].value;
    if (p == -1)
      root = &tree[i];
    else
      tree[p - 1].insert(&tree[i]);
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> ar[i].first;
    ar[i].second = i;
  }
  std::sort(ar, ar + k);
  build_tree(root);
  solve(root, -(1LL << 60), 1LL << 60, 0, 0);
  for (int i = 0; i < k; i++) printf("%.10lf\n", ans[i]);
  return 0;
}
