using namespace std; #include void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout< inline bool chmax(ll& a, ll b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(ll& a, ll b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, star,fini) for (int i = star; i < fini; i++) #define ALL(x) std::begin(x), std::end(x) #define INF ((1LL<<62)-(1LL<<31)) #define bit(x,i)(((x)>>(i))&1) long double distance(long double xi,long double yi,long double xj,long double yj){return sqrt(1.0*((xi-xj)*(xi-xj))+1.0*((yi-yj)*(yi-yj)));} ll n,m,p,q; long long modpow(long long a, long long n) { ll mod = p; long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a) { return modpow(a, p - 2); } void _main(){ cin >> n >> m >> p >> q; while (q--) { ll x,f;cin >> x >> f; ll xwf = (x%p)*modinv(f)%p; ll g_xwf = modinv(xwf); assert(f!=0); if(g_xwf>m){ cout<<0<