#include<stdio.h>#include<string.h>using namespace std;#define LL long long int main(){ int i, ca, t1, t2, t3, q; LL y, m, l, t, lm, rm, ans; scanf( "%d", &ca ); while( ca -- ) { scanf( "%d%d%d%d", &t1, &t2, &t3, &q ); for( i = 0; i < q; i ++ ) { scanf( "%lld%lld", &y, &m ); l = t1*(y-1); t = (l+t2-1)%t2 + 1; lm = t2*m - t; rm = lm + t2; lm = lm > t1 ? t1 : lm; lm = lm < 0 ? 0 : lm; rm = rm > t1 ? t1 : rm; rm = rm < 0 ? 0 : rm; ans = rm / t3 - lm / t3; printf( "%lldn", ans ); } } return 0;}


