#include <fstream>
#include <vector>
using namespace std;
const int N=16001;
struct etc{int x,y;} q[N];
int lin[N],col[N],T[2][N],Te[N],n;
vector<short int> v[3*N];
bool par;
ifstream in("zoo.in");
ofstream out("zoo.out");
inline bool cmp(const etc &a,const etc &b)
{
return a.x<b.x;
}
int bs(int v[],int x)
{
int i,step=1<<13;
for (i=0;step;step>>=1)
if (i+step<=v[0] && v[i+step]<=x)
i+=step;
return i;
}
void update(int poz,int st,int dr,int x,int val)
{
if (st==dr)
{
v[poz].push_back(val);
return;
}
int m=(st+dr)>>1,S=poz<<1,D=S+1;
if (x<=m)
update(S,st,m,x,val);
else
update(D,m+1,dr,x,val);
v[poz].clear();
int A=v[S].size()-1,B=v[D].size()-1;
for (int i=0,j=0;i<=A || j<=B;)
if (j>B || i<=A && v[S][i]<=v[D][j])
v[poz].push_back(v[S][i++]);
else
v[poz].push_back(v[D][j++]);
}
void query(int poz,int st,int dr,int x,int y)
{
if (x<=st && y>=dr)
{
par=!par;
T[par][0]=0;
for (unsigned int i=1,j=0;i<=T[!par][0] || j<v[poz].size();)
if (j>=v[poz].size() || i<=T[!par][0] && T[!par][i]<=v[poz][j])
T[par][++T[par][0]]=T[!par][i++];
else
T[par][++T[par][0]]=v[poz][j++];
return;
}
int m=(st+dr)>>1,S=poz<<1,D=S+1;
if (x<=m)
query(S,st,m,x,y);
if (m<y)
query(D,m+1,dr,x,y);
}
void normalizare()
{
int i;
for (i=1;i<=n;i++)
Te[i]=q[i].x;
sort(Te+1,Te+n+1);
lin[++lin[0]]=Te[1];
for (i=2;i<=n;i++)
if (Te[i]!=Te[i-1])
lin[++lin[0]]=Te[i];
for (i=1;i<=n;i++)
Te[i]=q[i].y;
sort(Te+1,Te+n+1);
col[++col[0]]=Te[1];
for (i=2;i<=n;i++)
if (Te[i]!=Te[i-1])
col[++col[0]]=Te[i];
sort(q+1,q+n+1,cmp);
for (i=1;i<=n;i++)
update(1,1,n,bs(lin,q[i].x),bs(col,q[i].y));
}
int main()
{
int x,y,z,t,times;
in>>n;
for (int i=1;i<=n;i++)
in>>q[i].x>>q[i].y;
normalizare();
in>>times;
while (times--)
{
in>>x>>y>>z>>t;
x=bs(lin,x);z=bs(lin,z);
y=bs(col,y);t=bs(col,t);
T[par][0]=0;
query(1,1,n,x,z);
out<<bs(T[par],t)-bs(T[par],y-1)<<"\n";
}
return 0;
}