#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1 << 14;
class ArbInt{
struct Nod{
short int pozSt, pozDr;
Nod(short int pozSt = 0, short int pozDr = 0) :
pozSt(pozSt),
pozDr(pozDr)
{}
};
vector<Nod> aint[3 * N];
public:
ArbInt(){
for (int i = 1 ; i < 3 * N ; i++)
aint[i].push_back( Nod() );
}
void update(int x, int y, int poz = 1, int st = 1, int dr = N){
if (st == dr){
aint[poz].push_back( Nod() );
return;
}
int m = (st + dr) >> 1;
if (x <= m)
update(x, y, poz << 1, st, m);
else
update(x, y, 1 + (poz << 1), m + 1, dr);
aint[poz].push_back( Nod( aint[poz << 1].size() - 1, aint[1 + (poz << 1)].size() - 1 ) );
}
int query(int x, int y, int pMin, int pMax, int poz = 1, int st = 1, int dr = N){
if (x <= st && dr <= y)
return pMax - pMin;
int ans = 0, m = (st + dr) >> 1;
if (x <= m)
ans += query(x, y, aint[poz][pMin].pozSt, aint[poz][pMax].pozSt, poz << 1, st, m);
if (m < y)
ans += query(x, y, aint[poz][pMin].pozDr, aint[poz][pMax].pozDr, 1 + (poz << 1), m + 1, dr);
return ans;
}
};
struct Punct{
int x, y;
inline bool operator<(const Punct& P) const {
return y < P.y;
}
};
int X[N], Y[N], n;
Punct P[N];
ArbInt A;
int find(int v[], int x){
int ans = 0;
for (int step = (N >> 1) ; step ; step >>= 1)
if (ans + step <= n && v[ans + step] <= x)
ans += step;
return ans;
}
void update(int x, int y){
A.update( find(X, x), find(Y, y) );
}
int query(int x, int y, int z, int t){
x = find(X, x - 1) + 1;
z = find(X, z);
if (z < x)
return 0;
return A.query( x, z, find(Y, y - 1), find(Y, t) );
}
int main(){
ifstream in("zoo.in");
ofstream out("zoo.out");
in >> n;
for (int i = 1 ; i <= n ; i++){
in >> P[i].x >> P[i].y;
X[i] = P[i].x;
}
sort(P + 1, P + n + 1);
sort(X + 1, X + n + 1);
for (int i = 1 ; i <= n ; i++)
Y[i] = P[i].y;
for (int i = 1 ; i <= n ; i++)
update( P[i].x, P[i].y );
int nrQ, x, y, z, t;
in >> nrQ;
while (nrQ--){
in >> x >> y >> z >> t;
out << query(x, y, z, t) << '\n';
}
out.close();
in.close();
return 0;
}