Problem: You are given a convex polygon. Count, please, the number of triangles that contain a given point in the plane and their vertices are the vertices of the polygon. It is guaranteed, that the point doesn't lie on the sides and the diagonals of the polygon.

Input

The first line contains integer n — the number of vertices of the polygon (3 ≤ n ≤ 100000). The polygon description is following: n lines containing coordinates of the vertices in clockwise order (integer x and y not greater than 109 by absolute value). It is guaranteed that the given polygon is nondegenerate and convex (no three points lie on the same line).

The next line contains integer t (1 ≤ t ≤ 20) — the number of points which you should count the answer for. It is followed by t lines with coordinates of the points (integer x and y not greater than 109 by absolute value).

Output

The output should contain t integer numbers, each on a separate line, where i-th number is the answer for the i-th point.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Examples

Input

4
5 0
0 0
0 5
5 5
1
1 3


Output

2


Input

3
0 0
0 5
5 0
2
1 1
10 10


Output

1
0


Input

5
7 6
6 3
4 1
1 2
2 4
4
3 3
2 3
5 5
4 2


Output

5
3
3
4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5 + 5;
long long n, t;
long long a, b, wynik1, wynik2;
struct Point {
  long long x, y;
  Point(long long x = 0, long long y = 0) : x(x), y(y) {}
  bool operator==(Point &a) { return a.x == x && a.y == y; }
};
inline long long Det(Point a, Point b, Point c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
inline bool comp(Point a, Point b) {
  if (a.x < b.x) return 1;
  if (a.x == b.x) {
    if (a.y == b.y) return 1;
    if (a.y < b.y) return 1;
    return 0;
  }
  return 0;
}
int sgn(long long x) {
  if (x > 0) return 1;
  if (x < 0) return -1;
  return 0;
}
inline bool Punkt_w_srodku_prostokata(Point p1, Point p2, Point p3) {
  return (min(p1.x, p2.x) < p3.x && min(p1.y, p2.y) < p3.y &&
          max(p1.x, p2.x) > p3.x && max(p1.y, p2.y) > p3.y);
}
inline bool Punkt_w_srodku_prostokata_i_na_obwodzie(Point p1, Point p2,
                                                    Point p3) {
  return (min(p1.x, p2.x) <= p3.x && min(p1.y, p2.y) <= p3.y &&
          max(p1.x, p2.x) >= p3.x && max(p1.y, p2.y) >= p3.y);
}
inline bool Punkt_w_odcinku(Point p1, Point p2, Point l) {
  return (Det(p1, p2, l) == 0 && Punkt_w_srodku_prostokata(p1, p2, l) == 1);
}
inline bool Punkt_na_odcinku(Point p1, Point p2, Point l) {
  return (Det(p1, p2, l) == 0 &&
          Punkt_w_srodku_prostokata_i_na_obwodzie(p1, p2, l) == 1);
}
inline bool czy_odcinek_przecina_sie_z_odcinkiem(Point p1, Point p2, Point l1,
                                                 Point l2) {
  return sgn(Det(p1, p2, l1)) * sgn(Det(p1, p2, l2)) == -1 &&
         sgn(Det(l1, l2, p1)) * sgn(Det(l1, l2, p2)) == -1;
}
inline bool czy_punkt_jest_w_wielokacie(vector<Point> l, Point p) {
  long long v = 0;
  int second = n;
  Point d(1024141014, p.y + 1);
  for (int i = 0; i < second; i++) {
    v += czy_odcinek_przecina_sie_z_odcinkiem(p, d, l[i], l[(i + 1) % second]);
  }
  return v & 1;
}
vector<Point> tab;
vector<Point> pom;
int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &a, &b);
    tab.push_back(Point(a, b));
  }
  for (int i = 0; i < n; i++) {
    tab.push_back(tab[i]);
  }
  scanf("%lld", &t);
  for (int j = 0; j < t; j++) {
    scanf("%lld%lld", &a, &b);
    Point gdzie(a, b);
    wynik1 = n * (n - 1) * (n - 2) / 6;
    wynik2 = 0;
    if (czy_punkt_jest_w_wielokacie(tab, gdzie) == false) {
      printf("0\n");
      continue;
    }
    for (int i = 0; i < n; i++) {
      long long p1 = i + 1, k1 = i + n - 1, i1 = -1, i2 = -1;
      while (p1 <= k1) {
        long long srodek = (p1 + k1) / 2;
        if (Det(tab[i], tab[srodek], gdzie) > 0) {
          k1 = srodek - 1;
          i1 = srodek;
        } else {
          p1 = srodek + 1;
        }
      }
      long long pc = abs(i1 - i) - 1;
      wynik2 += pc * (pc - 1) / 2;
    }
    printf("%lld\n", wynik1 - wynik2);
  }
  return 0;
}