/*
给出一个凸多边形n<=100000,t个询问
每个询问,问凸多边形有多少个三角形包含点(x,y)
看解题报告的
O(n)算法
总三角形个数 - 不包含(x,y)的三角形个数
代码看 252170 Ra16bit
*/
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<string>
using namespace std;
const int INF = 1000000000;
const int MAXN = 100010;
struct Point
{
double x ,y;
void read()
{
scanf("%lf%lf",&x,&y);
}
};
Point pt[MAXN*2];
double cross(Point A , Point B , Point O)
{
return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}
int main()
{
//freopen("in","r",stdin);
for(int n;~scanf("%d",&n);)
{
for(int i = 0 ; i < n ; i ++)
{
pt[i].read();
pt[i+n] = pt[i];
}
int t;
scanf("%d",&t);
while(t--)
{
Point xy;
xy.read();
bool flag = false;
for(int i = 0 ; i < n ; i ++)
{
if(cross(pt[i+1] , xy , pt[i] ) >= 0 )
{
flag = true;
break;
}
}
if(flag)
{
puts("0");
continue;
}
__int64 ans = (__int64)n*(n-1)*(n-2)/6;//C(n,3)
for(int i = 0 , j = 2 ; i < n ; i++)
{
while(cross( xy,pt[j] , pt[i]) > 0)
{
j++;
}
ans -= (__int64)(j-1-i)*(j-1-i-1)/2;//C(j-1-i , 2)
}
printf("%I64d\n",ans);
}
}
return 0;
}