from heapq import heappush, heappop, heapify INF = 1 << 60 N = int(input()) A = list(map(int, input().split())) Q = int(input()) X = list(map(int, input().split())) min_mod = max(A) + 1 prev_tot = sum(A) q = [-a for a in A] heapify(q) for x in X: if min_mod < x: print(prev_tot) continue tot = prev_tot ys = [] while q and -q[0] >= x: y = -heappop(q) tot -= y m = y % x if m > 0: ys.append(m) tot += m print(tot) prev_tot = tot for y in ys: heappush(q, -y) min_mod = min(min_mod, x)