#include using namespace std; #define int long long long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main(){ int N,M,P,Q; cin>>N>>M>>P>>Q; for(int i=0;i>x>>t; x %= P; int p = P; int z = gcd(p,x); p /= z; x /= z; if(p == 1){ cout<= M){ int ans = 0; while(k <= M){ ans++; k += p; } cout<