import heapq n = int(input()) a = [int(i) for i in input().split()] q = int(input()) x = [int(i) for i in input().split()] qry = x[0] li = [] heapq.heapify(li) now = 0 for i in range(n): tmp = a[i] % qry if tmp != 0: now += tmp heapq.heappush(li,-tmp) print(now) for i in range(q-1): qry = x[i+1] f = True while len(li) and f == True: tmp = heapq.heappop(li) if -tmp >= qry: now -= -tmp tmp = (-tmp) % qry now += tmp if tmp != 0: heapq.heappush(li,-tmp) else: f = False heapq.heappush(li,tmp) print(now)