n = int(input()) a = list(map(int, input().split())) q = int(input()) x_list = list(map(int, input().split())) current_sum = sum(a) active = list(range(n)) # Indices of active elements (non-zero) for x in x_list: new_active = [] delta = 0 # The total change in sum due to this query for idx in active: orig = a[idx] if orig == 0: continue # Skip if already zero (though this shouldn't happen as per active list) new_val = orig % x delta += new_val - orig a[idx] = new_val if new_val != 0: new_active.append(idx) current_sum += delta print(current_sum) active = new_active # Update active list for next query