#include <bits/stdc++.h>
using namespace std;
struct point {
  long long x, y;
  point(long long x = 0, long long y = 0) : x(x), y(y) {}
  void read() { scanf("%I64d%I64d", &x, &y); }
  point operator-(point b) { return point(x - b.x, y - b.y); }
};
vector<point> ev;
int n;
long long ans = 0;
bool on_watch(point p, point q) {
  long long t = p.x * q.y - p.y * q.x;
  return t < 0;
}
bool stop(int a, int b, point c) { return !on_watch(ev[b] - ev[a], c - ev[a]); }
long long count(long long n) { return n * (n - 1) / 2; }
long long get_full() { return (n * (n - 1ll) * (n - 2ll)) / 6ll; }
long long triangle_square(point a, point b, point c) {
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
long long square(point c) {
  long long sq = 0;
  for (int i = 0; i < n; ++i) {
    sq += abs(triangle_square(ev[i], ev[(i + 1) % n], c));
  }
  return sq;
}
int main() {
  int test;
  scanf("%d", &n);
  long long full = get_full();
  ev.resize(n);
  for (int i = 0; i < n; ++i) ev[i].read();
  scanf("%d", &test);
  for (int t = 0; t < test; ++t) {
    long long ans = 0, next = 1;
    point q;
    q.read();
    if (square(ev[0]) != square(q)) {
      printf("0\n");
      continue;
    }
    for (int i = 0; i < n; ++i) {
      while (!stop(i, (1 + next) % n, q)) ++next;
      ans += count(next - i);
    }
    cout << full - ans << endl;
  }
  return 0;
}
