#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) int main() { int n; cin >> n; map> problem; rep(i, n) { int a, b; cin >> a >> b; problem[a].push_back(b); } int q; cin >> q; rep(i, q) { int x, y; cin >> x >> y; int ans = 0; for (auto it = problem.begin(); it != problem.end(); it++) { if (it->first > x) break; ans += it->second.size() - count(it->second.begin(), it->second.end(), y); } cout << ans << endl; } return 0; }