#include using namespace std; using ll=long long; using pll=pair; using tll=tuple; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> n >> m >> p >> q; while(q--){ ll x,f; cin >> x >> f; if(x%p==0){ if(f==0) cout << m << '\n'; else cout << "0\n"; continue; } ll s=division(f,x,p); if(s==0) s+=p; if(s<=m) cout << 1+(m-s)/p << " "<< s << '\n'; else cout << "0\n"; } }