import bisect R,N=list(map(int,input().split())) A=list(map(int,input().split())) A=sorted(A) Q=int(input()) for i in range(Q): l,r=list(map(int,input().split())) if l//R==r//R: cl=bisect.bisect_left(A,l%R) cr=bisect.bisect_right(A,r%R) print(cr-cl) else: ans=((r//R)-(l//R)-1)*N cl=bisect.bisect_left(A,l%R) cr=bisect.bisect_right(A,r%R) ans=ans+cr+(N-cl) print(ans)