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