#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int qwq = 1 << 18;
int N, Q;
pair<long long, int> val[qwq];
long long A[qwq], B[qwq];
int pos[qwq], lvl[qwq];
long long smt[qwq], smi[qwq];
int cnt[qwq], cni[qwq];
int ans[qwq];
vector<pair<long long, int> > gr[qwq];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= (N); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    val[i] = make_pair(-b, a);
  }
  sort(val + 1, val + N + 1);
  scanf("%d", &Q);
  for (int i = 1; i <= (Q); ++i) scanf("%d", B + i);
  for (int i = 1; i <= (N); ++i) {
    A[i] = val[i].second;
    lvl[i] = 63 - __builtin_clzll(A[i]);
  }
  for (int i = (40); ((-1) > 0 ? i <= (0) : i >= (0)); i += (-1)) {
    for (int j = 1; j <= (N); ++j) {
      smt[j] = smt[j - 1] + A[j];
      smi[j] = smi[j - 1] + (lvl[j] != i) * A[j];
      cnt[j] = cnt[j - 1] + (A[j] > 0);
      cni[j] = cni[j - 1] + (lvl[j] < i);
      gr[j - 1].clear();
    }
    for (int j = 1; j <= (Q); ++j) {
      long long cs = smt[pos[j]] + B[j];
      int pp = upper_bound(smt + 1, smt + N + 1, cs) - smt - 1;
      if (pos[j] < pp) {
        ans[j] += cnt[pp] - cnt[pos[j]];
        B[j] -= smt[pp] - smt[pos[j]];
        pos[j] = pp;
      }
      if (pos[j] < N) gr[pos[j]].push_back(make_pair(B[j] + smi[pos[j]], j));
    }
    priority_queue<pair<long long, int> > pq;
    for (int j = 1; j <= (N); ++j) {
      for (int k = 0; k < (((int)(gr[j - 1]).size())); ++k)
        pq.push(gr[j - 1][k]);
      if (lvl[j] == i) {
        while (((int)(pq).size()) && pq.top().first >= smi[j] + A[j]) {
          pair<long long, int> pr = pq.top();
          pq.pop();
          int to = pr.second;
          B[to] = pr.first - smi[j] - A[j];
          ans[to] += cni[j] - cni[pos[to]] + 1;
          pos[to] = j;
        }
        A[j] = 0;
      }
    }
  }
  for (int i = 1; i <= (Q); ++i) {
    printf("%d%c", ans[i], " \n"[i == Q]);
  }
  return 0;
}
