from bisect import bisect_left, bisect_right r, n = map(int, input().split()) a = sorted(map(int, input().split())) def f(x): x, y = divmod(x, r) return x * n + bisect_left(a, y) for _ in range(int(input())): li, ri = map(int, input().split()) print(f(ri + 1) - f(li))