R, N = map(int, input().split()) A = list(map(int, input().split())) D = [0] * 2 * R for a in A: D[a] += 1 Dc = [0] * (2 * R + 1) for i in range(2 * R): Dc[i + 1] = Dc[i] + D[i] Q = int(input()) for _ in range(Q): l, r = map(int, input().split()) d = l // R l -= d * R r -= d * R diff = r - l ans = diff // R * N r -= diff // R * R ans += Dc[r] - Dc[l] print(ans)