import sys input = sys.stdin.readline R, N = map(int, input().split()) A = list(map(int, input().split())) Q = int(input()) LR = [list(map(int, input().split())) for _ in range(Q)] cnt = [0 for _ in range(R)] for a in A: cnt[a] += 1 S = [0] for c in cnt: S.append(S[-1]+c) for l, r in LR: rcnt = ((r+1)//R)*S[-1] + S[(r+1)%R] lcnt = (l//R)*S[-1] + S[l%R] ans = rcnt-lcnt print(ans)