from bisect import bisect_left, bisect_right X, N = map(int, input().split()) A = sorted(list(map(int, input().split()))) Q = int(input()) LR = [list(map(int, input().split())) for _ in range(Q)] for L, R in LR: if L//X == R//X: print(bisect_right(A, R%X)-bisect_left(A, L%X)) else: ans = (N-bisect_left(A, L%X))+bisect_right(A, R%X) if R//X-L//X >= 2: ans += N*(R//X-L//X-1) print(ans)