# include <algorithm>
# include <cstdio>
# include <vector>
using namespace std;
# define nS nod << 1
# define nD nS | 1
# define x first
# define y second
typedef pair <int, int> PR;
const char *FIN = "zoo.in", *FOU = "zoo.out";
const int MAX = 16005;
vector <int> ai[MAX << 2];
int N, M, x1, x2, y1, y2;
PR V[MAX];
void buildtree (int nod, int st, int dr) {
if (st == dr) {
ai[nod].resize (1, V[st].y);
return ;
}
int mij = st + dr >> 1;
buildtree (nS, st, mij);
buildtree (nD, mij + 1, dr);
ai[nod].resize (ai[nS].size () + ai[nD].size ());
merge (ai[nS].begin (), ai[nS].end (), ai[nD].begin (), ai[nD].end (), ai[nod].begin ());
}
int query (int nod, int st, int dr, int x1, int x2, int y1, int y2) {
if (x1 <= V[st].x && V[dr].x <= x2)
return lower_bound (ai[nod].begin (), ai[nod].end (), y2 + 1) - lower_bound (ai[nod].begin (), ai[nod].end (), y1);
if (st == dr) return 0;
int mij = st + dr >> 1;
if (V[mij | 1].x > x2) return query (nS, st, mij, x1, x2, y1, y2);
else if (V[mij].x < x1) return query (nD, mij + 1, dr, x1, x2, y1, y2);
else return query (nS, st, mij, x1, V[mij].x, y1, y2) + query (nD, mij + 1, dr, V[mij | 1].x, x2, y1, y2);
}
int main (void) {
freopen (FIN, "r", stdin);
freopen (FOU, "w", stdout);
scanf ("%d", &N);
for (int i = 0; i < N; ++i)
scanf ("%d %d", &V[i].x, &V[i].y);
sort (V, V + N);
buildtree (1, 0, N - 1);
for (scanf ("%d", &M); M; --M) {
scanf ("%d %d %d %d", &x1, &y1, &x2, &y2);
x1 = max (x1, V[0].x), x2 = min (x2, V[N - 1].x);
printf ("%d\n", query (1, 0, N - 1, x1, x2, y1, y2));
}
}