#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> a(n); for(auto &&[x, y, z] : a){ cin >> x >> y; z = -1; } int Q; cin >> Q; for(int i = 0; i < Q; i++){ int x, y; cin >> x >> y; a.emplace_back(x, y, i); } sort(a.begin(), a.end()); int tot = 0; vector ans(Q), cnt(100001); for(auto &&[x, y, z] : a){ if(z == -1){ cnt[y]++; tot++; }else{ ans[z] = tot - cnt[y]; } } for(auto &&v : ans) cout << v << '\n'; }