#include <bits/stdc++.h>
using namespace std;
const int maxn = 111111;
vector<int> edge[maxn];
int type[maxn];
int key[maxn];
int pre[maxn];
int Left[maxn];
int Right[maxn];
int Lkey[maxn];
int Rkey[maxn];
double ans[maxn];
bool leaf[maxn];
vector<int> vec;
void dfs(int rt) {
  Left[rt] = Right[rt] = -1;
  for (int i = 0; i < edge[rt].size(); i++) {
    int ch = edge[rt][i];
    if (key[ch] < key[rt])
      Left[rt] = ch, type[ch] = 1;
    else
      Right[rt] = ch, type[ch] = 2;
    dfs(ch);
  }
  if (Left[rt] == -1) {
    Lkey[rt] = Rkey[rt] = key[rt];
  } else {
    Lkey[rt] = Lkey[Left[rt]];
    Rkey[rt] = Rkey[Right[rt]];
  }
}
void dfs(int rt, double val, int cnt) {
  if (Left[rt] == -1) {
    leaf[rt] = true;
    vec.push_back(rt);
    ans[rt] = val / cnt;
  } else {
    dfs(Left[rt], val + Lkey[Right[rt]], cnt + 1);
    dfs(Right[rt], val + Rkey[Left[rt]], cnt + 1);
  }
}
int pos[maxn << 1], Euler[maxn << 1], LOG[maxn << 1];
int val[maxn << 1], dis[maxn];
int MIN[20][maxn << 2];
void dfs(int u, int &ID, int Dis, int pre) {
  pos[u] = ID;
  val[ID] = Dis;
  Euler[ID++] = u;
  dis[u] = Dis;
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (v == pre) continue;
    dfs(v, ID, Dis + 1, u);
    val[ID] = Dis, Euler[ID++] = u;
  }
}
void initRMQ(int n) {
  LOG[0] = -1;
  for (int i = 1; i <= n; i++) {
    MIN[0][i] = i;
    LOG[i] = (i & (i - 1)) ? LOG[i - 1] : LOG[i - 1] + 1;
  }
  for (int i = 1; i <= LOG[n]; i++) {
    int limit = n + 1 - (1 << i);
    for (int j = 1; j <= limit; j++) {
      if (val[MIN[i - 1][j]] < val[MIN[i - 1][j + (1 << i >> 1)]])
        MIN[i][j] = MIN[i - 1][j];
      else
        MIN[i][j] = MIN[i - 1][j + (1 << i >> 1)];
    }
  }
}
int GetAnces(int a, int b) {
  a = pos[a], b = pos[b];
  if (a > b) swap(a, b);
  int t = LOG[b - a + 1];
  b -= (1 << t) - 1;
  if (val[MIN[t][a]] < val[MIN[t][b]])
    return Euler[MIN[t][a]];
  else
    return Euler[MIN[t][b]];
}
int main() {
  int n;
  scanf("%d", &n);
  int root = -1;
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == -1)
      root = i;
    else
      edge[x].push_back(i);
    key[i] = y;
    pre[i] = x;
  }
  dfs(root);
  dfs(root, 0, 0);
  int one = 1;
  dfs(root, one, 0, -1);
  initRMQ(n * 2 - 1);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int x;
    scanf("%d", &x);
    int lo = 0, hi = vec.size() - 1;
    while (lo <= hi) {
      int mid = (lo + hi) >> 1;
      if (key[vec[mid]] < x)
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    if (hi == -1) {
      printf("%.10lf\n", ans[vec[0]]);
    } else if (hi == vec.size() - 1) {
      printf("%.10lf\n", ans[vec[hi]]);
    } else {
      int anc = GetAnces(vec[hi], vec[hi + 1]);
      if (x < key[anc])
        printf("%.10lf\n", ans[vec[hi]]);
      else
        printf("%.10lf\n", ans[vec[hi + 1]]);
    }
  }
  return 0;
}
