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 {
  int64_t x, y;
  pt() {}
  pt(int64_t _x, int64_t _y) : x(_x), y(_y) {}
  int64_t cross(const pt& p) const { return x * p.y - y * p.x; }
  int64_t cross(const pt& a, const pt& b) const {
    return (a - *this).cross(b - *this);
  }
  int64_t norm() const { return x * x + y * y; }
  pt operator-(const pt& p) const { return pt(x - p.x, y - p.y); }
};
int N;
vector<pt> seq;
bool lexComp(const pt& l, const pt& r) {
  return l.x < r.x || (l.x == r.x && l.y < r.y);
}
void prepare(vector<pt>& points) {
  N = points.size();
  int pos = 0;
  for (int i = 0; i < N; ++i)
    if (lexComp(points[i], points[pos])) pos = i;
  rotate(points.begin(), points.begin() + pos, points.end());
  N--;
  seq.resize(N);
  for (int i = 0; i < N; ++i) seq[i] = points[i + 1] - points[0];
}
bool inTriangle(pt a, pt b, pt c, pt point) {
  return abs(a.cross(b, c)) == abs(point.cross(a, b)) + abs(point.cross(b, c)) +
                                   abs(point.cross(c, a));
}
int sgn(int64_t val) { return val >= 0 ? val ? 1 : 0 : -1; }
bool inPolygon(pt point) {
  if (seq[0].cross(point) != 0 &&
      sgn(seq[0].cross(point)) != sgn(seq[0].cross(seq[N - 1])))
    return false;
  if (seq[N - 1].cross(point) != 0 &&
      sgn(seq[N - 1].cross(point)) != sgn(seq[N - 1].cross(seq[0])))
    return false;
  if (seq[0].cross(point) == 0) return seq[0].norm() >= point.norm();
  if (seq[N - 1].cross(point) == 0) return seq[N - 1].norm() >= point.norm();
  int l = 0, r = N - 1, m, pos;
  while (l <= r) {
    m = (l + r) / 2;
    if (seq[m].cross(point) <= 0)
      pos = m, l = m + 1;
    else
      r = m - 1;
  }
  return inTriangle(seq[pos], seq[pos + 1], pt(0, 0), point);
}
bool clockwise(pt p1, pt p2, pt p3) { return p1.cross(p2, p3) < 0; }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n;
  cin >> n;
  vector<pt> points(n);
  for (pt& p : points) cin >> p.x >> p.y;
  prepare(points);
  int t;
  cin >> t;
  auto solve = [&](pt point) -> int64_t {
    int cur = 0;
    int64_t ans = 0;
    for (int i = 0; cur < n; (++i) %= n) {
      if (i == cur) continue;
      if (!clockwise(points[cur], points[i], point)) {
        int upb = i - 1;
        int dist = upb - cur;
        if (dist < 0) dist += n;
        int64_t add = dist * 1ll * (dist - 1) / 2;
        if (add > 0) ans += add;
        ++cur, --i;
      }
    }
    return ans;
  };
  int64_t c3n = n * 1ll * (n - 1) / 2 * 1ll * (n - 2) / 3;
  while (t-- > 0) {
    pt point;
    cin >> point.x >> point.y;
    if (!inPolygon(point - points[0]))
      cout << 0;
    else
      cout << c3n - solve(point);
    cout << '\n';
  }
  return 0;
}