#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n;
long long ans[maxn], sum[maxn], ary[maxn];
void solve(int q) {
  long long dep = 1, idx = 1, nxt;
  long long tmp, res = 0, d = q;
  while (idx <= n) {
    nxt = idx + d <= n ? idx + d : n;
    tmp = sum[nxt] - sum[idx];
    res += tmp * dep;
    idx += d, dep++, d *= q;
  }
  printf("%lld ", ans[q] = res);
}
int main() {
  int qn, q;
  scanf("%d", &n);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%lld", ary + i);
  sort(ary + 1, ary + 1 + n, greater<int>());
  for (int(i) = (1); (i) <= (n); (i)++) sum[i] = ary[i] + sum[i - 1];
  scanf("%d", &qn);
  while (qn--) {
    scanf("%d", &q);
    if (ans[q])
      printf("%lld ", ans[q]);
    else
      solve(q);
  }
  return 0;
}
