R,n=map(int,input().split()) a=list(map(int,input().split())) c=[0]*(R+1) for v in a: c[v]+=1 for i in range(R): c[i]+=c[i-1] Q=int(input()) for _ in range(Q): l,r=map(int,input().split()) l+=1 r+=1 g=0 g+=c[R-1]*(r//R)+c[r%R-1] g-=c[R-1]*((l-1)//R)+c[(l-1)%R-1] print(g)