#include <stdio.h>
#include <algorithm>
#define IN "zoo.in"
#define OUT "zoo.out"
#define Lg 16005
#define Max(a,b) a>b?a:b
#define Min(a,b) a<b?a:b
using namespace std;
int *H[Lg*4];
int N,M,x1,x2,y1,y2,S,D,Sum;
struct pct
{
int x,y;
}A[Lg];
struct cmp
{
bool operator()(const pct &a, const pct &b)const
{
return a.x<b.x;
}
};
void citire()
{
scanf ("%d", &N);
for (int i=1;i<=N;i++)
scanf ("%d %d",&A[i].x, &A[i].y);
}
void build(int nod,int st,int dr)
{
H[nod]=new int[dr-st+1];
if (st==dr)
{
H[nod][0]=A[st].y;
return ;
}
int mij=(st+dr)>>1;
build(nod<<1, st, mij);
build(nod<<1|1, mij+1,dr);
int Ls=mij-st, i=0, Ns=nod<<1;
int Ld=dr-mij-1, j=0, Nd=nod<<1|1;
int num=0;
while (i<=Ls || j<=Ld)
if (i<=Ls && (H[Ns][i]<=H[Nd][j] || j>Ld))
H[nod][num++]=H[Ns][i++];
else
H[nod][num++]=H[Nd][j++];
}
int Se(int X,int *A,int st,int dr)
{
int N=dr;
int mij;
while (st<dr)
{
mij=(st+dr)>>1;
if (A[mij]>=X)
dr=mij-1;
else
st=mij+1;
}
st=Min(st,dr);
while (A[st]<X && st<=N)
st++;
return st-1<=0?0:st-1;
}
int De(int X,int *A,int st,int dr)
{
int N=dr;
int mij;
while (st<dr)
{
mij=(st+dr)>>1;
if (A[mij]>=X)
dr=mij-1;
else
st=mij+1;
}
st=Min(st,dr);
while (A[st]<=X && st<=N)
st++;
return st-1<=0?0:st-1;
}
void calc(int nod,int st,int dr)
{
if (S<=st && D>=dr)
{
Sum+=De(y2,H[nod],0,dr-st)+1-(Se(y1,H[nod],0,dr-st));
return ;
}
int mij=(st+dr)>>1;
if (S<=mij)
calc(nod<<1,st,mij);
if (D>mij)
calc(nod<<1|1,mij+1,dr);
}
int Pi(int X,int st,int dr)
{
int mij;
while (st<dr)
{
mij=(st+dr)>>1;
if (A[mij].x>=X)
dr=mij-1;
else
st=mij+1;
}
st=Min(st,dr);
while (A[st].x<X && st<=N)
st++;
return st-1<=0?1:st-1;
}
void afish()
{
scanf ("%d ",&M);
while (M--)
{
Sum=0;
scanf ("%d %d %d %d",&x1,&y1,&x2,&y2);
S=Pi(x1,1,N);
D=Pi(x2,1,N);
calc(1,1,N);
printf("%d\n",Sum);
}
}
int main ()
{
freopen (IN, "r", stdin);
freopen (OUT ,"w", stdout);
citire();
sort(A+1,A+N+1,cmp());
build(1,1,N);
afish();
return 0;
}