#include <bits/stdc++.h>
using namespace std;
int n;
long long x[100007], y[100007], xx, yy, m, p, q;
long long ans;
int get(int p, int q) {
  while ((x[q] - x[p]) * (yy - y[p]) - (y[q] - y[p]) * (xx - x[p]) <= 0)
    q = q % n + 1;
  q = (q + n - 2) % n + 1;
  return q;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%I64d%I64d", &x[i], &y[i]);
  for (cin >> m; m; m--) {
    cin >> xx >> yy;
    int now = 0;
    ans = 0;
    for (int i = 1; i <= n; i++)
      if ((xx - x[i]) * (y[i % n + 1] - y[i]) -
              (yy - y[i]) * (x[i % n + 1] - x[i]) <
          0)
        now++;
    if (now != 0 && now != n) {
      cout << 0 << endl;
      continue;
    }
    for (p = 1, q = get(1, 1); p <= n; p++, q = get(p, q)) {
      int r = ((q - p) % n + n) % n;
      ans += ((long long)r) * (r - 1) / 2;
    }
    ans = ((long long)n * (n - 1) * (n - 2) / 6 - ans);
    cout << ans << endl;
  }
  return 0;
}
