#include <bits/stdc++.h>
using namespace std;
struct A {
  int num, loc;
  bool leaf;
} arr[100005];
struct NODE {
  int son[2];
  int len;
} node[100005];
int data[100005], mx[100005], mn[100005];
void dfs(int u) {
  int v, len = node[u].len, i;
  mx[u] = mn[u] = data[u];
  for (i = 0; i < len; i++) {
    v = node[u].son[i];
    dfs(v);
    mx[u] = max(mx[u], mx[v]);
    mn[u] = min(mn[u], mn[v]);
  }
}
long long up;
int down;
int find_left(int u) {
  int v, len = node[u].len, i;
  for (i = 0; i < len; i++) {
    v = node[u].son[i];
    if (data[v] < data[u]) return v;
  }
  return -1;
}
int find_right(int u) {
  int v, len = node[u].len, i;
  for (i = 0; i < len; i++) {
    v = node[u].son[i];
    if (data[v] > data[u]) return v;
  }
  return -1;
}
double dp[100005];
void dfs2(int u) {
  int left = find_left(u), right = find_right(u);
  if (left == -1) {
    dp[u] = 1.0 * up / down;
    arr[u].leaf = 1;
    return;
  }
  up += mn[right];
  down++;
  dfs2(left);
  up -= mn[right];
  down--;
  up += mx[left];
  down++;
  dfs2(right);
  up -= mx[left];
  down--;
}
int n, loc[100005];
int bi(int key) {
  int left = 1, right = n, mid, ans = -1;
  while (left <= right) {
    mid = (left + right) >> 1;
    if (arr[mid].num < key) {
      ans = mid;
      left = mid + 1;
    } else
      right = mid - 1;
  }
  int ret;
  if (ans == -1) {
    return arr[1].loc;
  }
  if (arr[ans].leaf) {
    return arr[ans].loc;
  } else
    return arr[ans + 1].loc;
}
bool cmp(A a, A b) { return a.num < b.num; }
int main() {
  int i;
  scanf("%d", &n);
  int f, root;
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &f, data + i);
    arr[i].num = data[i];
    arr[i].loc = i;
    if (f == -1) {
      root = i;
      continue;
    }
    node[f].son[node[f].len++] = i;
  }
  dfs(root);
  up = down = 0;
  dfs2(root);
  sort(arr + 1, arr + n + 1, cmp);
  int k;
  scanf("%d", &k);
  for (i = 1; i <= k; i++) {
    scanf("%d", &f);
    printf("%.10lf\n", dp[bi(f)]);
  }
  return 0;
}
