#include <fstream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define MAX 16005
#define RMAX 100005
#define BMAX 50
#define INF 2000000050
#define PII pair<int, int>
#define f first
#define s second
#define mp make_pair
#define pb push_back
using namespace std;
int N, M, poz, val, X[MAX], Y[MAX], AIB[MAX], ans[RMAX];
char buff[BMAX];
PII V[MAX];
struct PUNCT
{
int X, Y, ind, sign;
}add, Q[RMAX << 2];
struct RECT
{
int x1, y1, x2, y2;
} R[RMAX];
inline void cit(int &X)
{
X = 0; int sign = 1;
while((buff[poz] < '0' || buff[poz] > '9') && buff[poz] != '-') poz++;
if(buff[poz] == '-') sign = -1, poz++;
while(buff[poz] >= '0' && buff[poz] <= '9')
X = X * 10 + buff[poz++] - '0';
X *= sign;
}
void citire()
{
ifstream in("zoo.in");
in.getline(buff, BMAX); poz = 0; cit(N);
for(int i = 1; i <= N; i++) in.getline(buff, BMAX), poz = 0, cit(V[i].f), cit(V[i].s);
in.getline(buff, BMAX); poz = 0; cit(M); sort(V + 1, V + N + 1);
for(int i = 1; i <= M; i++)
{
in.getline(buff, BMAX); poz = 0;
cit(R[i].x1), cit(R[i].y1), cit(R[i].x2), cit(R[i].y2);
} in.close();
}
int BS(int X, int *V, bool T)
{
int i =0, pas = 1 << 18;
for(i = 0; pas; pas >>= 1)
if(i + pas <= V[0] && V[i + pas] < X) i += pas;
if(!T) return i;
if(V[i + 1] == X) return i + 1;
return i;
}
void normalize()
{
Y[++Y[0]] = -INF;
for(int i = 1; i <= N; i++) Y[++Y[0]] = V[i].s;
Y[++Y[0]] = INF; sort(Y + 1, Y + Y[0] + 1);
for(int i = 1; i <= Y[0]; i++)
{
X[i] = X[i - 1];
if(Y[i] != Y[i - 1]) X[i]++;
}
for(int i = 1; i <= N; i++) V[i].s = X[BS(V[i].s, Y, 1)];
for(int i = 1; i <= M; i++)
{
R[i].y1 = X[BS(R[i].y1, Y, 0)];
R[i].y2 = X[BS(R[i].y2, Y, 1)];
}
}
bool cmp(PUNCT a, PUNCT b)
{
return a.X < b.X;
}
void adauga()
{
val = 0;
for(int i = 1; i <= M; i++)
{
++val;
Q[val].X = R[i].x1 - 1, Q[val].Y = R[i].y1, Q[val].ind = i, Q[val].sign = 1;
++val;
Q[val].X = R[i].x2, Q[val].Y = R[i].y2, Q[val].ind = i, Q[val].sign = 1;
++val;
Q[val].X = R[i].x2, Q[val].Y = R[i].y1, Q[val].ind = i, Q[val].sign = -1;
++val;
Q[val].X = R[i].x1 - 1, Q[val].Y = R[i].y2, Q[val].ind = i, Q[val].sign = -1;
} sort(Q + 1, Q + val + 1, cmp);
}
inline void update(const int &Y)
{
for(int i = Y; i < N; i += (i & (-i)))
AIB[i]++;
}
inline int query(const int &Y)
{
int rez = 0;
for(int i = Y; i; i -= (i & (-i)))
rez += AIB[i];
return rez;
}
int main()
{
citire();
normalize();
adauga();
for(int i = 1, ind = 1; i <= val; i++)
{
for(; V[ind].f <= Q[i].X && ind <= N; ind++)
update(V[ind].s);
ans[Q[i].ind] += Q[i].sign * query(Q[i].Y);
}
ofstream out("zoo.out");
for(int i = 1; i <= M; i++) out<<ans[i]<<"\n";
out.close();
return 0;
}