import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long total = 0; PriorityQueue queue = new PriorityQueue(new Comparator() { public int compare(Integer i1, Integer i2) { return i2.intValue() - i1.intValue(); } }); for (int i = 0; i < n; i++) { int x = sc.nextInt(); total += x; queue.add(x); } int q = sc.nextInt(); int min = Integer.MAX_VALUE; StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int x = sc.nextInt(); if (x < min) { min = x; while(queue.peek() >= x) { int y = queue.poll(); total -= y / x * x; queue.add(y % x); } } sb.append(total).append("\n"); } System.out.print(sb); } }