#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
const int magic = 2500;
struct Node {
  int from, to, delta, add;
  Node(int from, int to, int delta, int add)
      : from(from), to(to), delta(delta), add(add) {}
};
int n, a[maxn], c[maxn], q[maxn], id[maxn], b[maxn], ans[maxn], Q;
vector<Node> All;
void BuildInterval() {
  for (auto&& x : All)
    for (int i = x.from; i <= x.to; ++i)
      b[id[i]] -= x.delta, ans[id[i]] += x.add;
  for (int i = 1; i <= Q; ++i) id[i] = i;
  sort(id + 1, id + Q + 1,
       [&](const int& x, const int& y) { return b[x] < b[y]; });
  All.clear();
  All.push_back(Node(1, Q, 0, 0));
}
int main(int argc, char* argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", c + i, q + i), id[i] = i;
  sort(id + 1, id + n + 1, [&](const int& x, const int& y) {
    return q[x] > q[y] || (q[x] == q[y] && c[x] < c[y]);
  });
  for (int i = 1; i <= n; ++i) a[i] = c[id[i]];
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) scanf("%d", b + i);
  BuildInterval();
  for (int i = 1; i <= n; ++i) {
    for (int j = 0, limit = All.size(); j < limit; ++j) {
      if (All[j].from > All[j].to) continue;
      if (b[id[All[j].from]] - All[j].delta >= a[i])
        All[j].delta += a[i], ++All[j].add;
      else if (b[id[All[j].to]] - All[j].delta >= a[i]) {
        int l = All[j].from + 1, r = All[j].to;
        while (l < r) {
          int mid = l + r >> 1;
          if (b[id[mid]] - All[j].delta >= a[i])
            r = mid;
          else
            l = mid + 1;
        }
        All.push_back(Node(l, All[j].to, All[j].delta + a[i], All[j].add + 1));
        All[j].to = l - 1;
      }
    }
    if (All.size() > magic || i == n) BuildInterval();
  }
  for (int i = 1; i <= Q; ++i) printf("%d ", ans[i]);
  puts("");
  return 0;
}
