from collections import deque, defaultdict as dd from random import randint from copy import deepcopy from heapq import heappop, heappush, heappushpop, heapify INF = 1 << 60 MOD = 1000000007 xor = randint(100, INF) def main(): r, n = map(int, input().split()) a = list(map(int, input().split())) ac = [0]*(2*r+1) for v in a: ac[v+1] += 1 ac[v+r+1] += 1 for i in range(2*r): ac[i+1] += ac[i] q = int(input()) for _ in range(q): x, y = map(int, input().split()) ans = ((y-x)//r)*n x %= r y %= r if x > y: y += r ans += ac[y+1]-ac[x] print(ans) if __name__ == "__main__": main()