#include <bits/stdc++.h>
using namespace std;
typedef struct point {
  double x, y;
  void read() { scanf("%lf%lf", &x, &y); }
} Point;
Point P[200001], X;
int n, m;
double cross(point p1, point p2, point p3) {
  return (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) P[i].read(), P[i + n] = P[i];
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    X.read();
    int id = 1;
    long long ans = 1ll * (n) * (n - 1) * (n - 2) / 6;
    for (int i = 0; i < n; i++)
      if (cross(P[i], P[i + 1], X) >= 1e-12) {
        ans = 0ll;
        goto ou;
      }
    for (int i = 0; i < n; i++) {
      if (id == i) id = i + 1;
      while (id < i + n && cross(X, P[i], P[id]) < 1e-12) id++;
      ans -= 1ll * (id - i - 1) * (id - i - 2) / 2ll;
    }
  ou:
    printf("%I64d\n", ans);
  }
  return 0;
}
