#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct Pt {
  int x, y;
  Pt() {}
  Pt(int _x, int _y) : x(_x), y(_y) {}
  void input() { scanf("%d%d", &x, &y); }
  Pt operator-(const Pt& pt) const { return Pt(x - pt.x, y - pt.y); }
  long long operator*(const Pt& pt) const {
    return (long long)x * pt.y - (long long)y * pt.x;
  }
} p[maxn];
int main() {
  int n, Q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) p[i].input();
  scanf("%d", &Q);
  while (Q--) {
    Pt pt;
    pt.input();
    long long ans = 0;
    bool over = false;
    for (int i = 0; i < n; i++) {
      if (((p[i] - pt) * (p[(i + 1) % n] - pt)) > 0) {
        over = true;
        break;
      }
    }
    if (over) {
      printf("%I64d\n", ans);
      continue;
    }
    int x = 1;
    for (int i = 0; i < n; i++) {
      while (x != i && ((pt - p[x]) * (p[i] - pt)) <= 0) x = (x + 1) % n;
      int cnt = (i - x + n) % n;
      ans += (long long)cnt * (cnt - 1) / 2;
    }
    ans = (long long)n * (n - 1) * (n - 2) / 6 - ans;
    printf("%I64d\n", ans);
  }
  return 0;
}
