#include <bits/stdc++.h>
using namespace std;
struct Shirt {
  int quality;
  int price;
  inline bool operator<(const Shirt &x) const {
    return (quality < x.quality) || (quality == x.quality && price > x.price);
  }
};
Shirt v[200000];
struct Query {
  int budget;
  int pointer;
  inline bool operator<(const Query &x) const { return budget < x.budget; }
} Q[200000];
struct SqrtUpdate {
  int lo, hi;
  int delta, shirts;
} vec[2 * 512];
int nUpdates;
int numShirts[200000];
int marsDelta[200000 + 1], marsShirts[200000 + 1];
void PushUpdates(const int M) {
  memset(marsDelta, 0, 4 * M);
  memset(marsShirts, 0, 4 * M);
  for (int i = 0; i < nUpdates; i++) {
    marsDelta[vec[i].lo] -= vec[i].delta;
    marsDelta[vec[i].hi + 1] += vec[i].delta;
    marsShirts[vec[i].lo] += vec[i].shirts;
    marsShirts[vec[i].hi + 1] -= vec[i].shirts;
  }
  nUpdates = 1;
  vec[0].lo = 0;
  vec[0].hi = M;
  vec[0].delta = 0;
  vec[0].shirts = 0;
  int partialSumDelta = 0, partialSumShirts = 0;
  for (int i = 0; i < M; i++) {
    partialSumDelta += marsDelta[i];
    partialSumShirts += marsShirts[i];
    Q[i].budget += partialSumDelta;
    numShirts[Q[i].pointer] += partialSumShirts;
  }
  sort(Q, Q + M);
}
int binSearch(const SqrtUpdate &sQ, const int cost) {
  int st = sQ.lo - 1, fn = sQ.hi + 1;
  while (fn - st > 1) {
    int mid = (fn + st) / 2;
    if (Q[mid].budget - sQ.delta >= cost) {
      fn = mid;
    } else {
      st = mid;
    }
  }
  return fn;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &v[i].price, &v[i].quality);
  }
  sort(v, v + N);
  int M;
  scanf("%d", &M);
  for (int i = 0; i < M; i++) {
    scanf("%d", &Q[i].budget);
    Q[i].pointer = i;
  }
  PushUpdates(M);
  for (int i = N - 1; i >= 0; i--) {
    int theta = nUpdates;
    for (int j = 0; j < nUpdates; j++) {
      const int firstCustomer = binSearch(vec[j], v[i].price);
      if (firstCustomer == vec[j].lo) {
        vec[j].delta += v[i].price;
        vec[j].shirts++;
      } else if (firstCustomer <= vec[j].hi) {
        vec[theta].lo = firstCustomer;
        vec[theta].hi = vec[j].hi;
        vec[theta].delta = vec[j].delta + v[i].price;
        vec[theta].shirts = vec[j].shirts + 1;
        vec[j].hi = firstCustomer - 1;
        theta++;
      }
    }
    nUpdates = theta;
    if (nUpdates > 512) {
      PushUpdates(M);
    }
  }
  PushUpdates(M);
  for (int i = 0; i < M; i++) {
    printf("%d ", numShirts[i]);
  }
  putchar('\n');
  return 0;
}
