from bisect import bisect_right R, n = map(int, input().split()) A = list(map(int, input().split())) A.sort() def f(x): tot = (x // R) * n x %= R tot += bisect_right(A, x) return tot Q = int(input()) for _ in range(Q): l, r = map(int, input().split()) print(f(r) - f(l - 1))