import sys sys.setrecursionlimit(100000000) input = sys.stdin.readline MOD = 10 ** 9 + 7 INF = 10 ** 15 from heapq import heapify,heappop,heappush def main(): N = int(input()) A = list(map(int,input().split())) A = [-a for a in A] Q = int(input()) X = list(map(int,input().split())) ans = [0] * (Q + 1) ans[0] = -sum(A) heapify(A) for i,q in enumerate(X): while -A[0] >= q: a = -heappop(A) ans[i] -= (a//q) * q a %= q heappush(A,-a) ans[i + 1] = ans[i] print('\n'.join(map(str,ans[:-1]))) if __name__ == '__main__': main()