m, n = map(int, input().split()) c = [0] * m for i in list(map(int, input().split())): c[i] += 1 for i in range(1, m): c[i] += c[i - 1] for _ in range(int(input())): l, r = map(int, input().split()) l -= 1 l1, l2 = l % m, l // m r1, r2 = r % m, r // m ans = c[-1] * (r2 - l2) + c[r1] - c[l1] print(ans)