Problem: You are given a convex polygon. Count, please, the number of triangles that contain a given point in the plane and their vertices are the vertices of the polygon. It is guaranteed, that the point doesn't lie on the sides and the diagonals of the polygon.

Input

The first line contains integer n — the number of vertices of the polygon (3 ≤ n ≤ 100000). The polygon description is following: n lines containing coordinates of the vertices in clockwise order (integer x and y not greater than 109 by absolute value). It is guaranteed that the given polygon is nondegenerate and convex (no three points lie on the same line).

The next line contains integer t (1 ≤ t ≤ 20) — the number of points which you should count the answer for. It is followed by t lines with coordinates of the points (integer x and y not greater than 109 by absolute value).

Output

The output should contain t integer numbers, each on a separate line, where i-th number is the answer for the i-th point.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Examples

Input

4
5 0
0 0
0 5
5 5
1
1 3


Output

2


Input

3
0 0
0 5
5 0
2
1 1
10 10


Output

1
0


Input

5
7 6
6 3
4 1
1 2
2 4
4
3 3
2 3
5 5
4 2


Output

5
3
3
4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
#pragma GCC optimize("03")
using namespace std;
long long dot(complex<long long> a, complex<long long> b) {
  return real(conj(a) * b);
}
long long cross(complex<long long> a, complex<long long> b) {
  return imag(conj(a) * b);
}
int quad(complex<long long> x) {
  if (x.imag() >= 0 && x.real() > 0) return 0;
  if (x.imag() > 0 && x.real() <= 0) return 1;
  if (x.imag() <= 0 && x.real() < 0) return 2;
  return 3;
}
void angular_sort(vector<complex<long long> > &angs) {
  sort((angs).begin(), (angs).end(),
       [&](complex<long long> &a, complex<long long> &b) {
         if (quad(a) != quad(b)) return quad(a) < quad(b);
         return cross(a, b) > 0;
       });
}
enum { OUT, ON, IN };
int contains(const vector<complex<long long> > &P,
             const complex<long long> &p) {
  bool in = false;
  for (int i = 0, n = P.size(); i < n; ++i) {
    complex<long long> a = P[i] - p, b = P[((i + 1) % n)] - p;
    if (imag(a) > imag(b)) swap(a, b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a, b) < 0) in = !in;
    if (cross(a, b) == 0 && dot(a, b) <= 0) return ON;
  }
  return in ? IN : OUT;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<complex<long long> > p;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    p.push_back(complex<long long>(x, y));
  }
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long x, y;
    cin >> x >> y;
    complex<long long> pp = complex<long long>(x, y);
    if (contains(p, pp) != IN) {
      cout << (0) << '\n';
      continue;
    }
    vector<complex<long long> > angs;
    for (int j = 0; j < n; j++) {
      complex<long long> v = p[j] - pp;
      angs.push_back(v);
    }
    angular_sort(angs);
    for (int j = 0; j < n; j++) angs.push_back(angs[j]);
    long long act = 0, pos = 1;
    while (cross(angs[0], angs[pos]) > 0) pos++;
    long long r = pos;
    long long res = 0;
    for (int l = 1; l < pos; l++) {
      while (cross(angs[l], angs[r]) > 0) r++;
      act += (r - pos);
    }
    res += act;
    for (int j = 1; j < n; j++) {
      long long pa = pos;
      if (j == pos) pos++;
      while (cross(angs[j], angs[pos]) > 0) pos++;
      long long dif = pos - pa;
      long long p1 = pa - j;
      long long p2 = n - p1 - dif;
      act += (dif * (p2 - p1));
      res += act;
    }
    cout << (res / 3) << '\n';
  }
  return 0;
}