#include <bits/stdc++.h>
using namespace std;
struct rec {
  long long val, id;
} E[2000001];
bool cmp(rec a, rec b) { return a.val < b.val; }
long long a[2000001], ANS[2000010];
long long n;
long long calc(long long K) {
  long long cnt = n, tt = 1, Go = K;
  long long ans = 0;
  while (1) {
    ans += (a[cnt - 1] - a[max(cnt - Go - 1, 0LL)]) * tt;
    if (cnt - Go - 1 <= 0) break;
    tt++;
    cnt -= Go;
    Go *= K;
  }
  return ans;
}
int main() {
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (long long i = 2; i <= n; i++) a[i] += a[i - 1];
  long long q;
  scanf("%I64d", &q);
  for (long long i = 1; i <= q; i++) {
    scanf("%I64d", &E[i].val);
    E[i].id = i;
  }
  sort(E + 1, E + 1 + q, cmp);
  long long j;
  for (long long i = 1; i <= q; i = j) {
    long long ans = calc(E[i].val);
    for (j = i; E[i].val == E[j].val && j <= q; j++) {
      ANS[E[j].id] = ans;
    }
  }
  for (long long i = 1; i <= q; i++) printf("%I64d\n", ANS[i]);
}
