#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& pp) {
  out << "(" << pp.first << "," << pp.second << ")";
  return out;
}
template <typename A, typename B>
istream& operator<<(istream& in, pair<A, B>& pp) {
  cerr << "A pair wanted" << endl;
  in >> pp.first >> pp.second;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& vect) {
  out << "length = " << vect.size() << endl;
  for (int i = 0; i < vect.size(); i++) out << vect[i] << " ";
  out << endl;
  return out;
}
ostream& operator<<(ostream& out, const vector<string>& vect) {
  out << vect.size() << " X " << vect[0].length() << endl;
  for (int i = 0; i < vect.size(); i++) out << vect[i] << endl;
  return out;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& vect) {
  vect.clear();
  int n;
  cerr << "A integer of length wanted" << endl;
  in >> n;
  vect.resize(n);
  cerr << n << " elements wanted" << endl;
  for (int i = 0; i < n; i++) in >> vect[i];
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& vect) {
  out << "row number=" << vect.size() << endl;
  for (int i = 0; i < vect.size(); i++) {
    out << "row #" << i << ":";
    for (int j = 0; j < vect[i].size(); j++) out << " " << vect[i][j];
    out << endl;
  }
  return out;
}
template <typename T>
istream& operator>>(istream& in, vector<vector<T> >& vect) {
  vect.clear();
  int n, m;
  cerr << "Two integers wanted" << endl;
  in >> n >> m;
  vect.resize(n);
  cerr << "A matrix " << n << " X " << m << " wanted" << endl;
  for (int i = 0; i < n; i++) {
    vect[i].resize(m);
    for (int j = 0; j < m; j++) in >> vect[i][j];
  }
  return in;
}
template <typename T>
inline void updateMax(T& a, const T& b) {
  a = max(a, b);
}
template <typename T>
inline void updateMin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
inline vector<T> erase(vector<T> table, int ind) {
  assert(ind < table.size());
  table.erase(table.begin() + ind);
  return table;
}
template <typename T>
vector<T> unique(vector<T> table) {
  sort(table.begin(), table.end());
  return vector<T>(table.begin(), unique(table.begin(), table.end()));
}
template <class T>
vector<T> parse(const string& ss, const char* cut = " ") {
  vector<T> re;
  for (int j = 0; j < ss.size(); j++) {
    string s;
    while (j < ss.size() && NULL == strchr(cut, ss[j])) s += ss[j++];
    if (!s.empty()) {
      T tmp;
      istringstream is(s);
      is >> tmp;
      re.push_back(tmp);
    }
  }
  return re;
}
template <typename T>
T __gcd(T n, T m, T& a, T& b) {
  T a1 = 0, b1 = 1;
  a = 1, b = 0;
  while (m) {
    T c = n / m;
    T r = n - m * c;
    T t;
    t = a;
    a = a1;
    a1 = t - c * a1;
    t = b;
    b = b1;
    b1 = t - c * b1;
    n = m;
    m = r;
  }
  return n;
}
struct Node {
  int r, c, d;
  int v;
  Node(int x, int y, int z, int v1) : r(x), c(y), d(z), v(v1){};
  bool operator<(const Node& other) const { return v > other.v; };
};
priority_queue<Node> heap;
const int dir[][2] = {{-1, 0}, {0, 1},  {1, 0},  {0, -1},
                      {1, 1},  {1, -1}, {-1, 1}, {-1, -1}};
const char dname[] = "NWSE";
const double EPS = 1e-15;
const double eps = 1e-10;
const double PI = acos(-1.0);
double mysqrt(double v) {
  if (v < EPS) return 0.0;
  return sqrt(v);
}
template <typename T>
double length(complex<T> p) {
  return sqrt(1.0 * p.real() * p.real() + 1.0 * p.imag() * p.imag());
}
template <typename T>
double dnorm(complex<T> p) {
  return (1.0 * p.real() * p.real() + 1.0 * p.imag() * p.imag());
}
int sigcross(long long int x1, long long int y1, long long int x2,
             long long int y2, long long int x3, long long int y3) {
  long long int re = (long long int)(x1 - x3) * (y2 - y3) -
                     (long long int)(y1 - y3) * (x2 - x3);
  if (re < 0) return -1;
  if (re > 0) return 1;
  return 0;
}
template <typename T>
long long int llcross(complex<T> p1, complex<T> p2) {
  return (long long int)p1.real() * (long long int)p2.imag() -
         (long long int)p2.real() * (long long int)p1.imag();
}
template <typename T>
int sigcross(complex<T> p1, complex<T> p2) {
  long long int re = llcross(p1, p2);
  if (re < 0) return -1;
  if (re > 0) return 1;
  return 0;
}
template <typename T>
double dcross(complex<T> p1, complex<T> p2) {
  return 1.0 * p1.real() * p2.imag() - p2.real() * p1.imag();
}
template <typename T>
double ddot(complex<T> p1, complex<T> p2) {
  return 1.0 * p1.real() * p2.real() + 1.0 * p1.imag() * p2.imag();
}
template <typename T>
bool pointCmp(const complex<T>& p1, const complex<T>& p2) {
  return p1.real() < p2.real() ||
         (p1.real() == p2.real() && p1.imag() < p2.imag());
}
template <typename T>
bool operator<(const complex<T>& a, const complex<T>& b) {
  return a.real() < b.real() || (a.real() == b.real() && a.imag() < b.imag());
}
template <typename T>
class pointLess : public less<complex<T> > {
 public:
  bool operator()(const complex<T>& a, const complex<T>& b) const {
    return a < b;
  };
};
template <typename T>
class Matrix : public vector<vector<T> > {
  static T (*_add)(const T&, const T&);
  static T (*_mul)(const T&, const T&);
  static T _zero, _one;

 public:
  static void set_para(T (*add)(const T&, const T&),
                       T (*mul)(const T&, const T&), const T& zero,
                       const T& one) {
    _add = add;
    _mul = mul;
    _zero = zero;
    _one = one;
  };
  void resize(int n, int m) {
    this->resize(n);
    for (int i = 0; i < n; i++) this->at(i).resize(m);
  };
  Matrix() { vector<vector<T> >(); };
  Matrix(int n, int m) : vector<vector<T> >(n, vector<T>(m)){};
  Matrix(int n, int m, const T& v) : vector<vector<T> >(n, vector<T>(m, v)){};
  Matrix<T> operator+(const Matrix& other) const;
  Matrix<T> operator-(const Matrix& other) const;
  Matrix<T> operator*(const Matrix&) const;
  Matrix<T> power(long long int s) const;
  Matrix<T> power_sum(long long int s) const;
  static Matrix<T> ONE(int n, int m) {
    Matrix<T> res(n, m, _zero);
    for (int i = 0; i < n; i++) res[i][i] = _one;
    return res;
  };
  static Matrix<T> ZERO(int n, int m) {
    Matrix<T> res(n, m, _zero);
    return res;
  };
};
template <typename T>
T (*Matrix<T>::_add)
(const T&, const T&) = NULL;
template <typename T>
T (*Matrix<T>::_mul)
(const T&, const T&) = NULL;
template <typename T>
T Matrix<T>::_zero;
template <typename T>
T Matrix<T>::_one;
template <typename T>
Matrix<T> Matrix<T>::power(long long int s) const {
  assert(this->size() == this->at(0).size());
  Matrix<T> res = Matrix<T>::ONE(this->size(), this->at(0).size());
  Matrix<T> t = *this;
  assert(s >= 0);
  while (s) {
    if (1 & s) res = res * t;
    t = t * t;
    s >>= 1;
  }
  return res;
}
template <typename T>
Matrix<T> Matrix<T>::power_sum(long long int s) const {
  assert(this->size == this->at(0).size());
  if (s == 1) return *this;
  if (s == 0) return Matrix<T>::ZERO(this->size(), this->size());
  long long int mid = s / 2;
  Matrix<T> low = power_sum(mid);
  Matrix<T> high;
  if (s - mid > mid)
    high = low + power(s - mid);
  else
    high = low;
  high = high * power(mid);
  return low + high;
}
template <typename T>
Matrix<T> Matrix<T>::operator*(const Matrix& b) const {
  const Matrix<T>& a = *this;
  const int n = a.size();
  assert(n);
  int p = a[0].size();
  assert(p);
  assert(p == b.size());
  int m = b[0].size();
  assert(m);
  Matrix<T> res(n, m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      T t = _zero;
      for (int k = 0; k < p; k++) t = _add(t, _mul(a[i][k], b[k][j]));
      res[i][j] = t;
    }
  return res;
}
template <typename T>
Matrix<T> Matrix<T>::operator+(const Matrix& other) const {
  assert(this->size == other.size());
  assert(this->size() == 0 || this->at(0).size() == other[0].size());
  const int n = this->size();
  if (n == 0) return Matrix<T>();
  const int m = other[0].size();
  Matrix<T> res(n, m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) res[i][j] = _add((*this)[i][j], other[i][j]);
  return res;
}
template <typename T>
void update(int pos, T add, T tree[], int n) {
  while (pos <= n) tree[pos] += add, pos += ((((pos) ^ ((pos)-1)) & pos));
}
template <typename T>
T query(int pos, T tree[]) {
  T res = 0;
  while (pos) res += tree[pos], pos ^= ((((pos) ^ ((pos)-1)) & pos));
  return res;
}
struct Interval_tree {
  const static int N = 10000;
  int n;
  int tree[4 * N], flag[4 * N];
  void build_tree(int m);
  void build_tree(int low, int high, int ind);
  int query(int low, int high, int b, int e, int ind);
  int query(int b, int e);
  void update(int pos, int v);
  void update(int b, int e, int v);
};
int get_root(int a, vector<int>& root) {
  if (root[a] == -1) return a;
  return (root[a] = get_root(root[a], root));
}
template <typename T>
struct Edge {
  int a, b;
  T c;
  Edge(int _a, int _b, T _c) {
    a = _a;
    b = _b;
    c = _c;
  };
  bool operator<(const Edge<T>& other) const { return c < other.c; };
};
void update_interval(long long int a, long long int b, long long int& lower,
                     long long int& upper) {
  if (a == 0) {
    if (0 <= b) return;
    upper = -1, lower = 0;
    return;
  }
  if (a > 0) {
    if (b >= 0)
      upper = min(upper, b / a);
    else
      upper = min(upper, (b - a + 1) / a);
  } else {
    a = -a;
    b = -b;
    if (b >= 0)
      lower = max(lower, (b + a - 1) / a);
    else
      lower = max(lower, b / a);
  }
}
template <typename T, int N>
void init_bino(T com[N][N], bool take_mod = false,
               long long int mod = 1000000000000000000LL) {
  if (take_mod) {
    assert(mod > 0);
    com[0][0] = 1 % mod;
    for (int i = 1; i < N; i++) {
      com[i][0] = com[i][i] = 1 % mod;
      for (int j = 1; j < i; j++)
        com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]) % mod;
    }
  } else {
    com[0][0] = 1;
    for (int i = 1; i < N; i++) {
      com[i][0] = com[i][i] = 1;
      for (int j = 1; j < i; j++)
        com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]);
    }
  }
}
const int N = 100000;
int son[N][2], stop[N];
int smax[N], smin[N];
int value[N];
bool visited[N];
long long int sum[N];
int dep[N];
int main() {
  int n, m;
  cin >> n;
  vector<pair<int, int> > all(n);
  int root;
  for (int i = 0; i < n; i++) {
    int p, x;
    cin >> p >> x;
    p--;
    value[i] = x;
    if (p >= 0) {
      son[p][stop[p]++] = i;
    } else {
      root = i;
    }
    all[i] = pair<int, int>(x, i);
  }
  for (int i = 0; i < n; i++) {
    if (stop[i] == 0) continue;
    if (value[son[i][0]] > value[son[i][1]]) {
      swap(son[i][0], son[i][1]);
    }
  }
  sort(all.begin(), all.end());
  stack<int> st;
  st.push(root);
  while (st.size()) {
    int v = st.top();
    st.pop();
    if (visited[v]) {
      smax[v] = value[v];
      smin[v] = value[v];
      for (int i = 0; i < stop[v]; i++) smax[v] = max(smax[v], smax[son[v][i]]);
      for (int i = 0; i < stop[v]; i++) smin[v] = min(smin[v], smin[son[v][i]]);
    } else {
      visited[v] = true;
      st.push(v);
      for (int i = 0; i < stop[v]; i++) {
        st.push(son[v][i]);
      }
    }
  }
  queue<int> qq;
  qq.push(root);
  while (qq.size()) {
    int a = qq.front();
    qq.pop();
    if (stop[a] == 0) continue;
    int b = son[a][0], c = son[a][1];
    qq.push(b);
    qq.push(c);
    sum[b] = sum[a] + smin[c];
    sum[c] = sum[a] + smax[b];
    dep[b] = dep[c] = dep[a] + 1;
  };
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    ;
    pair<int, int> pp(x, -1);
    int pos = lower_bound(all.begin(), all.end(), pp) - all.begin();
    ;
    int end = -1;
    if (pos < n && stop[all[pos].second] == 0) end = all[pos].second;
    if (pos - 1 >= 0 && stop[all[pos - 1].second] == 0)
      end = all[pos - 1].second;
    ;
    assert(end >= 0 && end < n);
    printf("%.10lf\n", 1.0 * sum[end] / dep[end]);
  }
  return 0;
}
