#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
FILE *f = fopen("zoo.in","r");
FILE *g = fopen("zoo.out","w");
const int NMAX = 16000;
const int MMAX = 100000;
struct event{
int x;
int Y1,Y2;
int where;
int type;
bool operator < (const event &other)const{
if(x != other.x){
return x < other.x;
}
if(other.type != type){
return type < other.type;
}
if(Y1 != other.Y1){
return Y1 < other.Y1;
}
if(Y2 != other.Y2){
return Y2 < other.Y2;
}
return where < other.where;
}
};
int N;
int M;
int AIB[2 * (NMAX + MMAX) + 5];
int X[NMAX + 5];
int Y[NMAX + 5];
int X1[MMAX + 5];
int Y1[MMAX + 5];
int X2[MMAX + 5];
int Y2[MMAX + 5];
int R[MMAX + 5];
vector<event> V;
map<int,int> Ma;
void u(int pos){
for(;pos <= (int)Ma.size();pos += (-pos) & pos){
AIB[pos]++;
}
}
int q(int pos){
int rez = 0;
for(;pos;pos -= (pos) & -pos){
rez += AIB[pos];
}
return rez;
}
int main(){
fscanf(f,"%d",&N);
for(int i = 1;i <= N;i++){
fscanf(f,"%d %d",&X[i],&Y[i]);
Ma[X[i]] = 1;
Ma[Y[i]] = 1;
}
fscanf(f,"%d",&M);
for(int i = 1;i <= M;i++){
fscanf(f,"%d %d %d %d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
Ma[X1[i]] = 1;
Ma[Y1[i]] = 1;
Ma[X2[i]] = 1;
Ma[Y2[i]] = 1;
}
int tmp = 0;
for(auto &it:Ma){
it.second = ++tmp;
}
for(int i = 1;i <= N;i++){
X[i] = Ma[X[i]];
Y[i] = Ma[Y[i]];
V.push_back({X[i],Y[i],0,0,0});
}
for(int i = 1;i <= M;i++){
X1[i] = Ma[X1[i]];
Y1[i] = Ma[Y1[i]];
X2[i] = Ma[X2[i]];
Y2[i] = Ma[Y2[i]];
V.push_back({X1[i],Y1[i],Y2[i],i,-1});
V.push_back({X2[i],Y1[i],Y2[i],i,1});
}
sort(V.begin(),V.end());
for(auto it:V){
if(it.type == 0){
u(it.Y1);
}
else{
R[it.where] += (q(it.Y2) - q(it.Y1 - 1)) * it.type;
}
}
for(int i = 1;i <= M;i++){
fprintf(g,"%d\n",R[i]);
}
fclose(f);
fclose(g);
return 0;
}