import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heappop, heappush, heapify N = int(readline()) *A, = map(int,readline().split()) Q = int(readline()) *X, = map(int,readline().split()) q = [-x for x in A] heapify(q) S = sum(A) answers = [] for x in X: while -q[0] >= x: a = -heappop(q) r = a % x S -= (a - r) heappush(q, -r) answers.append(S) print('\n'.join(map(str, answers)))