#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=20000000000000; ll mod=998244353; int main(){ ll n,m,p,q; cin >> n >> m >> p >> q; vectora; for (ll i = 0; i < q; i++) { ll x,f; cin >> x >> f; if (x%p==0) { if (f==0) { a.push_back(m); }else{ a.push_back(0); } continue; } ll z=f*inv_mod(x,p); z%=p; ll ans=m/p; if (z<=m%p&&z!=0) { ans++; } a.push_back(ans); } for (ll i = 0; i < a.size(); i++) { cout << a[i] <