#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int RB = 1e9;
int n, k;
pair<int, int> z[N];
struct Tshirt {
  int c, q, id;
  long long s;
  bool operator<(const Tshirt &b) const {
    if (q != b.q) return q > b.q;
    return c < b.c;
  }
} a[N];
inline int cmp2(int x, int y) {
  if (a[x].q != a[y].q)
    return a[x].q > a[y].q;
  else
    return a[x].c < a[y].c;
}
int rt;
struct fhq_treap {
  long long pos[N];
  int ch[N][2], rnd[N], val[N], mxn[N], siz[N];
  int tot;
  inline int new_node() {
    ++tot;
    ch[tot][0] = ch[tot][1] = mxn[tot] = val[tot] = pos[tot] = 0;
    siz[tot] = 1;
    rnd[tot] = rand();
    return tot;
  }
  void init() {
    mxn[0] = 0;
    tot = 0;
    rt = new_node();
  }
  inline void push_up(int x) {
    mxn[x] = max(max(mxn[ch[x][0]], mxn[ch[x][1]]), val[x]);
    siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1;
  }
  inline int merge(int x, int y) {
    if (x * y == 0) return x | y;
    if (rnd[x] < rnd[y]) {
      ch[x][1] = merge(ch[x][1], y);
      push_up(x);
      return x;
    } else {
      ch[y][0] = merge(x, ch[y][0]);
      push_up(y);
      return y;
    }
  }
  inline void split(int cur, long long k, int &x, int &y) {
    if (cur == 0) {
      x = y = 0;
      return;
    }
    if (pos[cur] <= k) {
      x = cur;
      split(ch[cur][1], k, ch[x][1], y);
    } else {
      y = cur;
      split(ch[cur][0], k, x, ch[y][0]);
    }
    push_up(cur);
  }
  inline void split_siz(int cur, int rk, int &x, int &y) {
    if (cur == 0) {
      x = y = 0;
      return;
    }
    if (siz[ch[cur][0]] + 1 <= rk) {
      x = cur;
      split_siz(ch[cur][1], rk - siz[ch[cur][0]] - 1, ch[x][1], y);
    } else {
      y = cur;
      split_siz(ch[cur][0], rk, x, ch[y][0]);
    }
    push_up(cur);
  }
  inline void insert(long long z, int id) {
    int w = new_node();
    mxn[w] = val[w] = id;
    pos[w] = z;
    int x, y;
    split(rt, z, x, y);
    rt = merge(merge(x, w), y);
  }
  inline void erase(long long z) {
    int x, y, q;
    split(rt, z - 1, x, y);
    split_siz(y, 1, y, q);
    rt = merge(x, q);
    return;
  }
  inline int query(long long z) {
    int x, y;
    split(rt, z, x, y);
    int ret = mxn[x];
    rt = merge(x, y);
    return ret;
  }
} t;
vector<int> vec[32];
int ans[N];
long long b[32];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].c, &a[i].q);
  scanf("%d", &k);
  for (int i = 1; i <= k; ++i) scanf("%d", &z[i].first), z[i].second = i;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) a[i].id = i;
  for (int i = 1; i <= n; ++i) {
    int curj = 0;
    for (int j = 0; j <= 31; ++j)
      if (a[i].c / 2 < (1 << j)) {
        curj = j;
        vec[j].push_back(i);
        break;
      }
    for (int j = 0; j <= curj - 1; ++j) a[i].s += b[j];
    a[i].s += a[i].c;
    b[curj] += a[i].c;
  }
  for (int j = 31; j >= 0; --j) {
    if (vec[j].empty()) continue;
    sort(vec[j].begin(), vec[j].end(), cmp2);
    sort(z + 1, z + k + 1);
    t.init();
    for (int i = 0; i <= (int)vec[j].size() - 1; ++i) {
      t.insert(a[vec[j][i]].s, vec[j].size() - i);
    }
    int w = 0;
    long long cursum = 0;
    for (int i = 1; i <= k; ++i) {
      z[i].first -= cursum;
      while (w < (int)vec[j].size() && a[vec[j][w]].s <= z[i].first) {
        cursum += a[vec[j][w]].c;
        z[i].first -= a[vec[j][w]].c;
        t.erase(a[vec[j][w]].s);
        ++w;
      }
      ans[z[i].second] += w;
      if (t.query(z[i].first) > 0) {
        int curi = vec[j].size() - t.query(z[i].first);
        z[i].first -= a[vec[j][curi]].c;
        ans[z[i].second]++;
      }
    }
  }
  for (int i = 1; i <= k; ++i) printf("%d%c", ans[i], i == k ? '\n' : ' ');
  return 0;
}
