#include using namespace std; typedef long long ll; typedef pair P; #define REP(i,n) for(int i=0;i b[100010]; int main(void){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int i,j; int N; cin >> N; vector a(N); REP(i,N){ int A,B; cin >> A >> B; b[B].push_back(A); a[i]=A; } sort(a.begin(),a.end()); for(i=1;i<=100000;i++) sort(b[i].begin(),b[i].end()); int Q; cin >> Q; while(Q--){ int X,Y; cin >> X >> Y; int x=upper_bound(a.begin(),a.end(),X)-a.begin(); vector d=b[Y]; int s=upper_bound(d.begin(),d.end(),X)-d.begin(); cout << x-s << "\n"; } return 0; }