#include using namespace std; #define For(i, a, b) for(int i = (a); i < (b); i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = (a); i >= (b); i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; struct SetupIo { SetupIo() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); } } setupio; int main() { int n; cin >> n; vector a(n), b(n); rep(i, n) { cin >> a[i] >> b[i]; } int q; cin >> q; vector x(q), y(q); rep(i, q) { cin >> x[i] >> y[i]; } vector diff = a; sort(ALL(diff)); vector ans(q, 0); rep(i, q) { int id = upper_bound(ALL(diff), x[i]) - diff.begin(); ans[i] = id; } map> mp; rep(i, n) { mp[b[i]].emplace_back(a[i]); } for (auto &[bunya, vec] : mp) { sort(ALL(vec)); } rep(i, q) { if (!mp.count(y[i])) { continue; } auto &vec = mp[y[i]]; int id = upper_bound(ALL(vec), x[i]) - vec.begin(); ans[i] -= id; } rep(i, q) { cout << ans[i] << "\n"; } }