// BISMILLAH // created by kamran // Date: 2026-01-06 02:19 #include using namespace std; #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define nl endl signed main() { fast; int n; cin>>n; map>x; for(int i=0;i>a>>b; x[b].push_back(a); } for(auto &i:x)sort(i.second.begin(),i.second.end()); int m; cin>>m; while(m--){ int a,b; cin>>a>>b; int ans=0; for(auto &i:x){ if(i.first == b)continue; else { int low=0; int high=i.second.size()-1; while(low<=high){ int mid=(high+low)/2; if(i.second[mid]>a)high=mid-1; else low=mid+1; } ans+=(low); } } cout<