from bisect import bisect_right, bisect_left def f(r): d, m = divmod(r, R) p = bisect_left(A, m+1) return d * N + p R, N = map(int, input().split()) A = list(map(int, input().split())) Q = int(input()) for _ in range(Q): l, r = map(int, input().split()) ans = f(r) - f(l-1) print(ans)