from heapq import heappop, heappush, heapify N = int(input()) *A, = map(int, input().split()) Q = int(input()) *X, = map(int, input().split()) B = [-a for a in A] heapify(B) def gen(A, B): res = sum(A) for x in X: while x <= -B[0]: d = -heappop(B) res += (d % x) - d heappush(B, -(d % x)) yield res print(*gen(A, B), sep='\n')