#include using namespace std; int inv(int x,int P) { int b=P-2; int e=1; while(b) { if(b&1)e=(long)e*x%P; b>>=1; x=(long)x*x%P; } return e; } int main() { int N,M,P,Q; cin>>N>>M>>P>>Q; for(;Q--;) { int x,f;cin>>x>>f; if(x%P==0) { if(f%P==0)cout<M)cout<<"0\n"; else if(y==0)cout<