def count(x): return (x // R) * N + table[x % R] R, N = map(int, input().split()) A = list(map(int, input().split())) table = [0] * (R + 1) for a in A: table[a] += 1 for i in range(1, R + 1): table[i] += table[i - 1] Q = int(input()) for _ in range(Q): l, r = map(int, input().split()) result = count(r) - count(l - 1) print(result)