import sys input = sys.stdin.readline from heapq import heappop,heappush N=int(input()) A=list(map(int,input().split())) Q=int(input()) X=list(map(int,input().split())) H=[] for a in A: heappush(H,-a) SUM=sum(A) for x in X: while True: if -H[0]>=x: k=-heappop(H) u=k%x SUM-=k-u heappush(H,-u) else: break print(SUM)