I,R=input,range J=lambda:map(int,I().split()) P,N=J() H=[0]*(P+1) F=H[:] for a in J():H[a]+=1 for j in R(1,P+1): i=j-1 F[j]=H[i] while i>j-(j&-j): F[j]+=F[i] i-=i&-i def L(r): a=0 i=min(r,P)+1 while i:a,i=a+F[i],i-(i&-i) return a def S(l,r): return L(r)-L(l-1) for _ in R(int(I())):l,r=J();d=l-l%P;r-=d;print(S(l-d,P-1)+L(P-1)*(r//P-1)+L(r%P))