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>
using namespace std;
const long long MOD = (long long)(1e9 + 7);
const long long INF = (long long)(1e9 + 10);
const int MAXN = (int)(2e5 + 5);
typedef long long tipo;
double EPS = (double)(1e-10);
struct punto {
  tipo x, y;
  punto const operator-(const punto &p) const { return {x - p.x, y - p.y}; }
  punto const operator+(const punto &p) const { return {x + p.x, y + p.y}; }
  tipo const operator*(const punto &p) const { return x * p.x + y * p.y; }
  tipo const operator^(const punto &p) const { return x * p.y - y * p.x; }
  bool const operator==(const punto &p) const {
    return (abs(x - p.x) < EPS && abs(y - p.y) < EPS);
  }
  tipo arg() { return atan2(y, x); }
  tipo mod() { return sqrtl(x * x + y * y); }
  tipo mod2() { return x * x + y * y; }
};
punto operator*(tipo k, const punto &p) { return {k * p.x, k * p.y}; }
ostream &operator<<(ostream &os, const punto &p) {
  return os << "(" << p.x << "," << p.y << ")";
}
istream &operator>>(istream &is, punto &p) { return is >> p.x >> p.y; }
long long solve(vector<punto> &p, punto query, long long n) {
  long long ans = 0;
  ans = n * (n - 1) * (n - 2) / 6;
  long long pos = 0, copia = 0;
  for (long long a = (0); a < (long long)(n); a++) {
    punto v1 = p[a] - query;
    punto v2 = p[pos] - p[a];
    while ((v1 ^ v2) <= 0) {
      pos = (pos + 1) % n;
      copia++;
      v2 = p[pos] - p[a];
    }
    ans -= (copia - a - 1) * (copia - a - 2) / 2;
  }
  return ans;
}
bool point_in_poly(vector<punto> &v, punto p) {
  unsigned i, j, mi, mj, c = 0;
  for (i = 0, j = v.size() - 1; i < v.size(); j = i++) {
    if ((v[i].y <= p.y && p.y < v[j].y) || (v[j].y <= p.y && p.y < v[i].y)) {
      mi = i;
      mj = j;
      if (v[mi].y > v[mj].y) swap(mi, mj);
      if (((p - v[mi]) ^ (v[mj] - v[mi])) < 0) c ^= 1;
    }
  }
  return c;
}
bool point_in_poly_convex(vector<punto> &v, punto p) {
  bool ans = true;
  if (((v[1] - v[0]) ^ (v[2] - v[1])) >= 0) reverse((v).begin(), (v).end());
  int a = 1, b = v.size() - 1;
  while (b - a > 1) {
    int med = (a + b) / 2;
    if (((v[med] - v[0]) ^ (p - v[med])) <= 0)
      a = med;
    else
      b = med;
  }
  if (((v[a] - v[0]) ^ (p - v[a])) > 0) ans = false;
  if (((v[b] - v[a]) ^ (p - v[b])) > 0) ans = false;
  if (((v[0] - v[b]) ^ (p - v[0])) > 0) ans = false;
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<long long, long long> > v(n);
  for (long long i = (0); i < (long long)(n); i++) {
    cin >> v[i].first >> v[i].second;
  }
  vector<punto> p(n);
  for (long long i = (0); i < (long long)(n); i++)
    p[i] = {v[i].first, v[i].second};
  int q;
  cin >> q;
  while (q--) {
    pair<long long, long long> point;
    cin >> point.first >> point.second;
    punto query = {point.first, point.second};
    bool d = point_in_poly_convex(p, query);
    if (d == false) {
      cout << "0\n";
      continue;
    }
    long long ans = solve(p, query, (long long)n);
    cout << ans << "\n";
  }
  return 0;
}