The big consignment of t-shirts goes on sale in the shop before the beginning of the spring. In all n types of t-shirts go on sale. The t-shirt of the i-th type has two integer parameters — ci and qi, where ci — is the price of the i-th type t-shirt, qi — is the quality of the i-th type t-shirt. It should be assumed that the unlimited number of t-shirts of each type goes on sale in the shop, but in general the quality is not concerned with the price. 

As predicted, k customers will come to the shop within the next month, the j-th customer will get ready to spend up to bj on buying t-shirts. 

All customers have the same strategy. First of all, the customer wants to buy the maximum possible number of the highest quality t-shirts, then to buy the maximum possible number of the highest quality t-shirts from residuary t-shirts and so on. At the same time among several same quality t-shirts the customer will buy one that is cheaper. The customers don't like the same t-shirts, so each customer will not buy more than one t-shirt of one type. 

Determine the number of t-shirts which each customer will buy, if they use the described strategy. All customers act independently from each other, and the purchase of one does not affect the purchase of another.

Input

The first line contains the positive integer n (1 ≤ n ≤ 2·105) — the number of t-shirt types. 

Each of the following n lines contains two integers ci and qi (1 ≤ ci, qi ≤ 109) — the price and the quality of the i-th type t-shirt.

The next line contains the positive integer k (1 ≤ k ≤ 2·105) — the number of the customers. 

The next line contains k positive integers b1, b2, ..., bk (1 ≤ bj ≤ 109), where the j-th number is equal to the sum, which the j-th customer gets ready to spend on t-shirts.

Output

The first line of the input data should contain the sequence of k integers, where the i-th number should be equal to the number of t-shirts, which the i-th customer will buy.

Examples

Input

3
7 5
3 5
4 3
2
13 14


Output

2 3 


Input

2
100 500
50 499
4
50 200 150 100


Output

1 2 2 1 

Note

In the first example the first customer will buy the t-shirt of the second type, then the t-shirt of the first type. He will spend 10 and will not be able to buy the t-shirt of the third type because it costs 4, and the customer will owe only 3. The second customer will buy all three t-shirts (at first, the t-shirt of the second type, then the t-shirt of the first type, and then the t-shirt of the third type). He will spend all money on it. 
#include <bits/stdc++.h>
using namespace std;
inline void read(int &n) {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  n = x * f;
}
int outputarray[20];
inline void write(int k) {
  int num = 0;
  if (k < 0) putchar('-'), k = -k;
  do {
    outputarray[++num] = k % 10, k /= 10;
  } while (k);
  while (num) putchar(outputarray[num--] + '0');
}
const int maxn = 200001;
int n, m, ans[maxn];
struct T {
  int p, q;
  bool operator<(const T &b) const { return q != b.q ? q > b.q : p < b.p; }
} s[maxn];
struct node {
  int key, id, l1, l2, s1, s2;
  node *l, *r;
  node(int w, int id) : s1(w), id(id) {
    key = rand();
    l1 = l2 = s2 = 0;
    l = r = NULL;
  }
  void pushdown() {
    if (l1) {
      if (l != NULL) l->l1 += l1, l->s1 += l1;
      if (r != NULL) r->l1 += l1, r->s1 += l1;
      l1 = 0;
    }
    if (l2) {
      if (l != NULL) l->l2 += l2, l->s2 += l2;
      if (r != NULL) r->l2 += l2, r->s2 += l2;
      l2 = 0;
    }
  }
};
void split(node *root, node *&a, node *&b, int v) {
  if (root == NULL) {
    a = b = NULL;
    return;
  }
  root->pushdown();
  if (root->s1 >= v)
    b = root, split(root->l, a, b->l, v);
  else
    a = root, split(root->r, a->r, b, v);
}
node *merge(node *a, node *b) {
  if (a == NULL) return b;
  if (b == NULL) return a;
  if (a->key < b->key) {
    a->pushdown(), a->r = merge(a->r, b);
    return a;
  }
  b->pushdown(), b->l = merge(a, b->l);
  return b;
}
node *insert(node *a, node *b) {
  if (a == NULL) return b;
  node *l, *r;
  split(a, l, r, b->s1);
  return merge(l, merge(b, r));
}
node *left(node *root) {
  while (root->l != NULL) {
    root->pushdown();
    root = root->l;
  }
  return root;
}
node *right(node *root) {
  while (root->r != NULL) {
    root->pushdown();
    root = root->r;
  }
  return root;
}
void updata(node *root, int v, int w) {
  root->l1 += v, root->l2 += w, root->s1 += v, root->s2 += w;
}
void query(node *root) {
  if (root == NULL) return;
  ans[root->id] = root->s2;
  root->pushdown();
  if (root->l != NULL) query(root->l);
  if (root->r != NULL) query(root->r);
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(s[i].p), read(s[i].q);
  sort(s + 1, s + n + 1);
  read(m);
  node *root = NULL;
  int k;
  for (int i = 1; i <= m; i++) {
    read(k);
    root = insert(root, new node(k, i));
  }
  node *l, *r, *x, *y, *L, *R;
  for (int i = 1; i <= n; i++) {
    split(root, l, r, s[i].p);
    if (r == NULL) {
      root = l;
      continue;
    }
    updata(r, -s[i].p, 1);
    if (l == NULL) {
      root = r;
      continue;
    }
    x = left(r), y = right(l);
    while (x->s1 < y->s1) {
      split(r, L, R, x->s1 + 1);
      l = insert(l, L), r = R;
      if (l == NULL || r == NULL) break;
      x = left(r), y = right(l);
    }
    root = merge(l, r);
  }
  query(root);
  for (int i = 1; i <= m; i++) write(ans[i]), putchar(' ');
  return 0;
}
