"""input""" #int-input # input = sys.stdin.readline def II(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(MI()) #str-input def SI(): return input() def MSI(): return input().split() def SI_L(): return list(SI()) def SI_LI(): return list(map(int, SI())) #multiple-input def LLI(n): return [LI() for _ in range(n)] def LSI(n): return [SI() for _ in range(n)] #1-indexを0-indexでinput def MI_1(): return map(lambda x:int(x)-1, input().split()) def TI_1(): return tuple(MI_1()) def LI_1(): return list(MI_1()) loop,n = MI() a = LI() a.sort() q = II() from bisect import bisect c = len(a) for i in range(q): l,r = MI() l -= 1 ans = c * (r//loop) + bisect(a,r%loop) ans -= c * (l//loop) + bisect(a,l%loop) print(ans)