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 double eps = 1e-2;
inline bool eq(double a, double b) { return abs(a - b) < eps; }
inline bool ls(double a, double b) { return a <= b - eps; }
inline bool gt(double a, double b) { return a >= b + eps; }
inline bool le(double a, double b) { return a < b + eps; }
inline bool ge(double a, double b) { return a > b - eps; }
inline bool zr(double lhs) { return fabs(lhs) < eps; }
inline bool nz(double lhs) { return fabs(lhs) >= eps; }
inline bool ps(double lhs) { return lhs >= eps; }
inline bool nn(double lhs) { return lhs >= -eps; }
inline bool ng(double lhs) { return lhs < -eps; }
inline bool np(double lhs) { return lhs < eps; }
struct Point {
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  void get() { scanf("%lf%lf", &x, &y); }
  void put() const { printf("(%lf, %lf)", x, y); }
};
struct Segment {
  Point a, b;
  Segment() : a(), b() {}
  Segment(Point a, Point b) : a(a), b(b) {}
};
struct Line {
  double A, B, C;
  Line() : A(0), B(0), C(0) {}
  Line(double A, double B, double C) : A(A), B(B), C(C) {}
  Line(const Point& lhs, const Point& rhs)
      : A(rhs.y - lhs.y), B(lhs.x - rhs.x), C(-(lhs.x * A + lhs.y * B)) {}
  Line(double slope, const Point& p)
      : A(slope), B(-1.0), C(p.y - slope * p.x) {}
  Line(const Point& p, double slope)
      : A(slope), B(-1.0), C(p.y - slope * p.x) {}
  Line(const Segment& s) { *this = Line(s.a, s.b); }
  double eval(const Point& p) const { return A * p.x + B * p.y + C; }
  void put() { printf("%lf %lf %lf\n", A, B, C); }
};
double operator^(const Point& lhs, const Point& rhs) {
  return lhs.x * rhs.y - lhs.y * rhs.x;
}
double operator*(const Point& lhs, const Point& rhs) {
  return lhs.x * rhs.x + lhs.y * rhs.y;
}
const Point operator-(const Point& lhs, const Point& rhs) {
  return Point(lhs.x - rhs.x, lhs.y - rhs.y);
}
bool onSegment(const Point& p, const Segment& s) {
  return zr((p - s.a) ^ (p - s.b)) && np((p - s.a) * (p - s.b));
}
const Point intersect(const Line& a, const Line& b) {
  return Point((a.B * b.C - b.B * a.C) / (b.B * a.A - a.B * b.A),
               (a.A * b.C - b.A * a.C) / (b.A * a.B - a.A * b.B));
}
Point x;
double dist(const Point& a, const Point& b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool Less(const Point& a, const Point& b) {
  Point hor(1, 0), va = a - x, vb = b - x;
  if ((va ^ vb) == 0 && va.x * vb.x > 0) {
    if (dist(va, x) < dist(vb, x))
      return 1;
    else
      return 0;
  }
  if ((va ^ hor) == 0) {
    if (va.x > 0 && !((vb ^ hor) == 0 && vb.x > 0)) return 1;
    if (va.x < 0 && (vb ^ hor) > 0) return 1;
    return 0;
  } else if ((va ^ hor) < 0) {
    if ((vb ^ hor) == 0 && vb.x < 0) return 1;
    if ((vb ^ hor) < 0 && (vb ^ va) < 0) return 1;
    if ((vb ^ hor) > 0) return 1;
    return 0;
  } else {
    if ((vb ^ va) < 0 && (vb ^ hor) > 0) return 1;
    return 0;
  }
}
void sortPolarCoor(vector<Point>& ps) { sort(ps.begin(), ps.end(), Less); }
bool inPolygon(vector<Point>& ps, Point p) {
  for (int i = 0; i <= (int)ps.size() - 1; i++) {
    int a = i, b = i == (int)ps.size() - 1 ? 0 : i + 1;
    Segment edge(ps[a], ps[b]);
    if (onSegment(p, edge)) return true;
  }
  double leftm = DBL_MAX;
  for (int i = 0; i <= (int)ps.size() - 1; i++) {
    if (ps[i].x < leftm) leftm = ps[i].x;
  }
  Segment ray(Point(min(leftm, p.x) - 100, p.y), p);
  int count = 0;
  for (int i = 0; i <= (int)ps.size() - 1; i++) {
    int a = i, b = i == (int)ps.size() - 1 ? 0 : i + 1;
    bool upa, upb;
    if (eq(ps[a].y, p.y) || gt(ps[a].y, p.y))
      upa = 1;
    else
      upa = 0;
    if (eq(ps[b].y, p.y) || gt(ps[b].y, p.y))
      upb = 1;
    else
      upb = 0;
    if (upa ^ upb) {
      Segment edge(ps[a], ps[b]);
      Point inter = intersect(Line(edge), Line(ray));
      if (onSegment(inter, edge) && onSegment(inter, ray)) count++;
    }
  }
  return count % 2 == 1;
}
bool inTriangle(const Point& a, const Point& b, const Point& c,
                const Point& x) {
  Point v1 = b - a, v2 = c - b, v3 = a - c;
  Point xa = x - a, xb = x - b, xc = x - c;
  int d1 = xa ^ v1, d2 = xb ^ v2, d3 = xc ^ v3;
  return d1 >> 31 == d2 >> 31 && d2 >> 31 == d3 >> 31;
}
vector<Point> poly;
int n;
inline int next(int i) {
  if (i == n - 1)
    return 0;
  else
    return i + 1;
}
inline int prev(int i) {
  if (i == 0)
    return n - 1;
  else
    return i - 1;
}
inline int dist(int i, int j) {
  if (i > j)
    return n + 1 - i + j;
  else
    return j - i + 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    double x, y;
    scanf("%lf%lf", &x, &y);
    poly.push_back({x, y});
  }
  long long t1 = (long long)n * (n - 1) * (n - 2) / 3 / 2;
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    double a;
    double b;
    scanf("%lf%lf", &a, &b);
    x = {a, b};
    if (inPolygon(poly, x) == 0) {
      printf("0\n");
      continue;
    }
    long long ans = 0;
    int z;
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        z = next(i);
        while (((poly[z] - poly[i]) ^ (x - poly[i])) < 0) {
          z = next(z);
        }
        z = prev(z);
      } else {
        if (z == i) z = next(i);
        while (((poly[z] - poly[i]) ^ (x - poly[i])) < 0) {
          z = next(z);
        }
        z = prev(z);
      }
      int num = dist(i, z);
      num -= 2;
      if (num >= 1) ans += (long long)(1 + num) * num / 2;
    }
    printf("%lld\n", t1 - ans);
  }
  return 0;
}