#include #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { int n; cin >> n; const int M = 100005; vector> to(M); rep(i, n) { int a, b; cin >> a >> b; to[0].push_back(a); to[b].push_back(a); } rep(i, M) ranges::sort(to[i]); auto ub = [&](int x, int y) { return ranges::upper_bound(to[y], x) - to[y].begin(); }; int q; cin >> q; rep(qi, q) { int x, y; cin >> x >> y; int ans = ub(x, 0) - ub(x, y); cout << ans << '\n'; } return 0; }