#include <bits/stdc++.h>
struct Point {
  long long x, y;
} a[100001];
long long cross(Point &a, Point &b, Point &c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
int main() {
  int n, t, i, j;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%I64d%I64d", &a[i].x, &a[i].y);
  a[n] = a[0];
  scanf("%d", &t);
  long long ans, k;
  Point p;
  while (t--) {
    scanf("%I64d%I64d", &p.x, &p.y);
    ans = (long long)n * (n - 1) * (n - 2) / 6;
    j = 1;
    for (i = 0; i < n; ++i) {
      if (cross(p, a[i], a[i + 1]) > 0) {
        ans = 0;
        break;
      }
      while (cross(p, a[i], a[j]) < 0) j = (j + 1) % n;
      k = (n + i - j - 1) % n;
      ans -= k * (k + 1) / 2;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
