#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5;
int x[N], y[N];
int px, py;
long long s(long long x1, long long y1, long long x2, long long y2) {
  return abs(x1 * y2 - y1 * x2);
}
bool inside(int a, int b, int c) {
  long long s4 = s(x[b] - x[a], y[b] - y[a], x[c] - x[a], y[c] - y[a]);
  long long s1 = s(x[b] - px, y[b] - py, x[c] - px, y[c] - py);
  long long s2 = s(x[c] - px, y[c] - py, x[a] - px, y[a] - py);
  long long s3 = s(x[a] - px, y[a] - py, x[b] - px, y[b] - py);
  return s1 + s2 + s3 == s4;
}
long long cn3(long long x) { return (x * (x - 1) * (x - 2)) / 6; }
long long cn2(long long x) { return (x * (x - 1)) / 2; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (int)n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    x[i + n] = x[i];
    y[i + n] = y[i];
  }
  int t = 1;
  scanf("%d", &t);
  for (int T = 0; T < (int)t; T++) {
    scanf("%d%d", &px, &py);
    long long ans = cn3(n);
    int l = 0;
    int r = 1;
    for (int i = 0; i < (int)n; i++) {
      while (r < 2 * n && !inside(l, r, r + 1)) r++;
      ans -= cn2(r - l);
      l++;
    }
    if (ans < 0) ans = 0;
    cout << ans << endl;
  }
  return 0;
}
