#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; V G[100100]; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; V A(n),B(n); rep(i,n){ cin>>A[i]>>B[i]; G[B[i]].push_back(A[i]); } sort(ALL(A)); rep(i,100100) sort(ALL(G[i])); int q; cin>>q; while(q--){ int a,b; cin>>a>>b; auto u=upper_bound(ALL(A),a)-A.begin(); auto g=upper_bound(ALL(G[b]),a)-G[b].begin(); cout<