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;
long long dot(pair<long long, long long> a, pair<long long, long long> b,
              pair<long long, long long> c) {
  pair<long long, long long> u = {b.first - a.first, b.second - a.second};
  pair<long long, long long> v = {c.first - a.first, c.second - a.second};
  return u.first * v.first + u.second * v.second;
}
long long cross(pair<long long, long long> a, pair<long long, long long> b,
                pair<long long, long long> c) {
  pair<long long, long long> u = {b.first - a.first, b.second - a.second};
  pair<long long, long long> v = {c.first - a.first, c.second - a.second};
  return u.first * v.second - u.second * v.first;
}
bool inside(vector<pair<long long, long long> > &v,
            pair<long long, long long> p) {
  int n = v.size(), start = 0;
  for (int i = 1; i < n; i++) {
    if (v[i].first < v[start].first ||
        (v[i].first == v[start].first && v[i].second < v[start].second))
      start = i;
  }
  rotate(v.begin(), v.begin() + start, v.end());
  if (cross(v[0], v[1], p) < 0) return false;
  if (cross(v[0], v[n - 1], p) > 0) return false;
  int l = 1, r = n - 2;
  while (l < r) {
    int m = (l + r + 1) / 2;
    if (cross(v[0], v[m], p) >= 0)
      l = m;
    else
      r = m - 1;
  }
  long long st = abs(cross(v[0], v[l], v[l + 1]));
  long long s1 = abs(cross(p, v[0], v[l]));
  long long s2 = abs(cross(p, v[l], v[l + 1]));
  long long s3 = abs(cross(p, v[l + 1], v[0]));
  if (st == s1 + s2 + s3) return true;
  return false;
}
long long f3(long long first) {
  return (first * (first - 1) * (first - 2)) / 6;
}
long long f2(long long first) { return (first * (first - 1)) / 2; }
long long solve(vector<pair<long long, long long> > &v,
                pair<long long, long long> p) {
  if (!inside(v, p)) {
    return 0;
  }
  int n = v.size();
  long long all = f3(n), cnt = 0;
  for (int pos = 0; pos < n; pos++) {
    int l = 1, r = n - 2;
    while (l < r) {
      int m = (r + l + 1) / 2;
      if (cross(v[pos], v[(pos + m) % n], p) >= 0)
        l = m;
      else
        r = m - 1;
    }
    cnt += f2(l) + f2(n - l - 1);
  }
  return all - (cnt / 2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, t;
  cin >> n;
  vector<pair<long long, long long> > v(n);
  for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  reverse(v.begin(), v.end());
  cin >> t;
  for (int i = 0; i < t; i++) {
    pair<long long, long long> p;
    cin >> p.first >> p.second;
    cout << solve(v, p) << "\n";
  }
  return 0;
}