from heapq import *

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
X = list(map(int, input().split()))
ans = sum(A)
H = []
for a in A:
    heappush(H, -a)

for x in X:
    while True:
        now = -heappop(H)
        if now < x:
            heappush(H, -now)
            break
        else:
            nex = now % x
            ans -= now - nex
            heappush(H, -nex)

    print(ans)