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;
struct pt {
  long long x, y;
  pt operator-(pt b) const { return {x - b.x, y - b.y}; }
  bool operator==(pt b) const { return x == b.x && y == b.y; }
  bool operator<(pt b) const {
    if (x != b.x) return x < b.x;
    return y < b.y;
  }
};
long long det(pt a, pt b, pt c) {
  return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x;
}
long long sq(long long x) { return x * x; }
long long d2(pt a, pt b) { return sq(a.x - b.x) + sq(a.y - b.y); }
long long sp(pt a, pt b) { return a.x * b.x + a.y * b.y; }
bool kolin(pt a, pt b, pt c) {
  if (det(a, b, c) != 0) return false;
  return b == a || b == c || sp(a - b, b - c) > 0;
}
long long sgn(long long x) {
  if (x < 0)
    return -1;
  else if (x == 0)
    return 0;
  else
    return 1;
}
bool sek(pt a, pt b, pt c, pt d) {
  return sgn(det(a, b, c)) * sgn(det(a, b, d)) == -1 &&
         sgn(det(c, d, a)) * sgn(det(c, d, b)) == -1;
}
bool pip(pt b, pt* a, int n) {
  long double w = 0;
  for (int i = 0; i < n; i++) {
    int j = (i + 1) % n;
    long double arg = sp(b - a[i], b - a[j]);
    arg /= sqrt(d2(b, a[i]));
    arg /= sqrt(d2(b, a[j]));
    arg = max(arg, (long double)-1);
    arg = min(arg, (long double)1);
    if (det(b, a[i], a[j]) < 0)
      w += acos(arg);
    else
      w -= acos(arg);
  }
  return abs(w) > 1.5;
}
long long area(pt* a, int n) {
  long long s = 0;
  for (int i = 1; i < n - 1; i++) s += det(a[0], a[i], a[i + 1]);
  return s;
}
basic_string<pt> hull_half(basic_string<pt> a) {
  basic_string<pt> b;
  for (pt p : a) {
    while (b.size() >= 2 && det(b[b.size() - 2], b[b.size() - 1], p) < 0)
      b.pop_back();
    b += p;
  }
  return b;
}
basic_string<pt> hull(basic_string<pt> a) {
  sort(a.begin(), a.end());
  auto p = hull_half(a);
  p.pop_back();
  reverse(a.begin(), a.end());
  auto q = hull_half(a);
  q.pop_back();
  return p + q;
}
int n;
pt a[100005], b;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
  int t;
  cin >> t;
  while (t--) {
    cin >> b.x >> b.y;
    int j = 1;
    bool ok = 1;
    for (int i = 0; i < n; i++)
      if (det(a[i], a[(i + 1) % n], b) > 0) ok = 0;
    if (!ok) {
      cout << "0\n";
      continue;
    }
    long long glavno = 0, sporedno = 0;
    for (int i = 0; i < n; i++) {
      while ((j + 1) % n != i && det(a[i], b, a[(j + 1) % n]) > 0)
        j = (j + 1) % n;
      long long k = j - i < 0 ? j - i + n : j - i;
      long long l = n - 1 - k;
      glavno += k * l;
      sporedno += k * (k - 1) / 2 + l * (l - 1) / 2;
      if (j == (i + 1) % n) j = (j + 1) % n;
    }
    cout << (glavno - sporedno / 2) / 3 << '\n';
  }
}