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-8;
int cmp(double x) {
  if (fabs(x) < eps) return 0;
  if (x > 0) return 1;
  return -1;
}
int cmp(double x, double y) { return cmp(x - y); }
inline double sqr(double x) { return x * x; }
struct point {
  double x, y;
  point() {}
  point(double a, double b) : x(a), y(b) {}
  friend point operator+(const point &a, const point &b) {
    return point(a.x + b.x, a.y + b.y);
  }
  friend point operator-(const point &a, const point &b) {
    return point(a.x - b.x, a.y - b.y);
  }
  friend bool operator==(const point &a, const point &b) {
    return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0;
  }
  friend bool operator<(const point &a, const point &b) {
    if (cmp(a.x - b.x) < 0) return true;
    if (cmp(a.x - b.x) > 0) return false;
    return cmp(a.y - b.y) < 0;
  }
  friend point operator*(const point &a, const double &b) {
    return point(a.x * b, a.y * b);
  }
  friend point operator*(const double &a, const point &b) {
    return point(a * b.x, a * b.y);
  }
  friend point operator/(const point &a, const double &b) {
    return point(a.x / b, a.y / b);
  }
  friend istream &operator>>(istream &fin, point &a) {
    fin >> a.x >> a.y;
    return fin;
  }
  double norm() { return sqrt(sqr(x) + sqr(y)); }
};
double det(const point &a, const point &b) { return a.x * b.y - a.y * b.x; }
double dot(const point &a, const point &b) { return a.x * b.x + a.y * b.y; }
double dist(const point &a, const point &b) { return (a - b).norm(); }
point rorate_point(const point &p, double A) {
  double tx = p.x, ty = p.y;
  return point(tx * cos(A) - ty * sin(A), tx * sin(A) + ty * cos(A));
}
struct line {
  point a, b;
  line(point x, point y) : a(x), b(y) {}
};
double dis_point_segment(const point p, const point s, const point t) {
  if (cmp(dot(p - s, t - s)) < 0) return (p - s).norm();
  if (cmp(dot(p - t, s - t)) < 0) return (p - t).norm();
  return fabs(det(s - p, t - p) / dist(s, t));
}
void PointProjLine(const point p, const point s, const point t, point &cp) {
  double r = dot((t - s), (p - s)) / dot(t - s, t - s);
  cp = s + r * (t - s);
}
bool PointOnSegment(point p, point s, point t) {
  return cmp(det(p - s, t - s)) == 0 && cmp(dot(p - s, p - t)) <= 0;
}
bool parallel(line a, line b) { return !cmp(det(a.a - a.b, b.a - b.b)); }
bool line_make_point(line a, line b, point &res) {
  if (parallel(a, b)) return false;
  double s1 = det(a.a - b.a, b.b - b.a);
  double s2 = det(a.b - b.a, b.b - b.a);
  res = (s1 * a.b - s2 * a.a) / (s1 - s2);
  return true;
}
double multiply(point sp, point ep, point op) {
  return ((sp.x - op.x) * (ep.y - op.y) - (ep.x - op.x) * (sp.y - op.y));
}
bool intersect(line u, line v) {
  return ((max(u.a.x, u.b.x) >= min(v.a.x, v.b.x)) &&
          (max(v.a.x, v.b.x) >= min(u.a.x, u.b.x)) &&
          (max(u.a.y, u.b.y) >= min(v.a.y, v.b.y)) &&
          (max(v.a.y, v.b.y) >= min(u.a.y, u.b.y)) &&
          (multiply(v.a, u.b, u.a) * multiply(u.b, v.b, u.a) >= 0) &&
          (multiply(u.a, v.b, v.a) * multiply(v.b, u.b, v.a) >= 0));
}
const int maxn = 10001;
struct polygon {
  int n;
  point a[maxn];
  double perimeter() {
    double sum = 0;
    a[n] = a[0];
    for (int i = 0; i < n; i++) sum += (a[i + 1] - a[i]).norm();
    return sum;
  }
  double area() {
    double sum = 0;
    a[n] = a[0];
    for (int i = 0; i < n; i++) sum += det(a[i + 1], a[i]);
    return sum / 2.;
  }
  int Point_In(point t) {
    int num = 0, i, d1, d2, k;
    a[n] = a[0];
    for (int i = 0; i < n; i++) {
      if (PointOnSegment(t, a[i], a[i + 1])) return 2;
      k = cmp(det(a[i + 1] - a[i], t - a[i]));
      d1 = cmp(a[i].y - t.y);
      d2 = cmp(a[i + 1].y - t.y);
      if (k > 0 && d1 <= 0 && d2 > 0) num++;
      if (k < 0 && d2 <= 0 && d1 > 0) num++;
    }
    return num & 1;
  }
};
struct polygon_convex {
  vector<point> P;
  polygon_convex(int Size = 0) { P.resize(Size); }
};
bool comp_less(const point &a, const point &b) {
  return cmp(a.x - b.x) < 0 || cmp(a.x - b.x) == 0 && cmp(a.y - b.y) < 0;
}
polygon_convex convex_hull(vector<point> a) {
  polygon_convex res(2 * a.size() + 5);
  sort(a.begin(), a.end(), comp_less);
  a.erase(unique(a.begin(), a.end()), a.end());
  int m = 0;
  for (int i = 0; i < a.size(); ++i) {
    while (m > 1 &&
           cmp(det(res.P[m - 1] - res.P[m - 2], a[i] - res.P[m - 2])) <= 0)
      --m;
    res.P[m++] = a[i];
  }
  int k = m;
  for (int i = int(a.size()) - 2; i >= 0; --i) {
    while (m > k &&
           cmp(det(res.P[m - 1] - res.P[m - 2], a[i] - res.P[m - 2])) <= 0)
      --m;
    res.P[m++] = a[i];
  }
  res.P.resize(m);
  if (a.size() > 1) res.P.resize(m - 1);
  return res;
}
int containOlogn(const polygon_convex &a, const point &b) {
  int n = a.P.size();
  point g = (a.P[0] + a.P[n / 3] + a.P[2 * n / 3]) / 3.0;
  int l = 0, r = n;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (cmp(det(a.P[l] - g, a.P[mid] - g)) > 0) {
      if (cmp(det(a.P[l] - g, b - g)) >= 0 && cmp(det(a.P[mid] - g, b - g)) < 0)
        r = mid;
      else
        l = mid;
    } else {
      if (cmp(det(a.P[l] - g, b - g)) < 0 && cmp(det(a.P[mid] - g, b - g)) >= 0)
        l = mid;
      else
        r = mid;
    }
  }
  r %= n;
  int z = cmp(det(a.P[r] - b, a.P[l] - b)) - 1;
  if (z == -2) return 1;
  return z;
}
bool containOn(const polygon_convex &a, const point &b) {
  int n = a.P.size();
  int sign = 0;
  for (int i = 0; i < n; ++i) {
    int x = cmp(det(a.P[i] - b, a.P[((i + 1) % n)] - b));
    if (x) {
      if (sign) {
        if (sign != x) return false;
      } else
        sign = x;
    }
  }
  return true;
}
bool inaline(line a, line b) {
  if (!parallel(a, b)) return false;
  if (cmp(det(a.a - a.b, a.a - b.a)) == 0) return true;
  return false;
}
long long t, n;
polygon_convex pol;
int main() {
  cin >> n;
  pol.P.resize(2 * n);
  for (int i = n - 1; i >= 0; --i) cin >> pol.P[i];
  for (int i = n; i < 2 * n; ++i) pol.P[i] = pol.P[i - n];
  cin >> t;
  while (t--) {
    long long mis = 0;
    point p;
    cin >> p;
    if (!containOlogn(pol, p)) {
      cout << 0 << endl;
      continue;
    }
    for (int i = 0; i < n; ++i) {
      long long l = i + 1, r = i + n - 1, mid;
      do {
        mid = (l + r) / 2;
        if (cmp(det(pol.P[i] - p, pol.P[mid] - p)) > 0)
          l = mid + 1;
        else
          r = mid;
      } while (l < r);
      l--;
      mis += (l - i) * (l - i - 1) / 2;
    }
    long long ans = n * (n - 1) * (n - 2) / 6;
    ans -= mis;
    cout << ans << endl;
  }
  return 0;
}