#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector> v(n); rep(i, n) cin >> v[i].first >> v[i].second; vector cnt(1e5 + 1, vector()); vector ps; for (auto [a, b] : v) { cnt[b].push_back(a); ps.push_back(a); } sort(ps.begin(), ps.end()); for (auto&& c : cnt) sort(c.begin(), c.end()); int q; cin >> q; while (q--) { int x, y; cin >> x >> y; auto idx1 = upper_bound(ps.begin(), ps.end(), x) - ps.begin(); auto idx2 = upper_bound(cnt[y].begin(), cnt[y].end(), x) - cnt[y].begin(); assert(idx1 >= idx2); cout << idx1 - idx2 << '\n'; } return 0; }