#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector tot; const int M = 1e5 + 5; vector> sep(M); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; tot.push_back(a); sep[b].push_back(a); } sort(tot.begin(), tot.end()); for (int i = 0; i < M; i++) { sort(sep[i].begin(), sep[i].end()); } int q; cin >> q; for (; q--;) { int x, y; cin >> x >> y; int ans = lower_bound(tot.begin(), tot.end(), x + 1) - tot.begin(); ans -= lower_bound(sep[y].begin(), sep[y].end(), x + 1) - sep[y].begin(); cout << ans << "\n"; } }