#include #include using namespace std; typedef long long ll; #define N (1<<24) #define M 100 int m, n, mx, ax, my, ay, mod, q; ll x[M], y[M], z[N]; bool prime[N]; int main(){ scanf("%d%d%d%d%d%d%d",&m,&n,&mx,&ax,&my,&ay,&mod); /*assert(1<=m&&m<=100); assert(m<=n&&n<=10000000); assert(1<=mod&&mod<=1<<23); assert(__builtin_popcount(mod)==1); assert(0<=mx&&mx 0; j-=i){ z[j/i] += z[j]; } } scanf("%d", &q); //assert(1<=q&&q<=100000); while(q--){ int a, b; scanf("%d%d",&a,&b); //assert(1<=a&&(ll)a<=1000000000/b&&a*b<=1000000000); b *= a; printf("%lld\n", z[a]-(b