#include <bits/stdc++.h>
using namespace std;
const int MAXN = 111111;
int n;
int a[MAXN];
long long sum[MAXN];
long long ans[MAXN];
int b[MAXN];
long long cal(int k) {
  long long ret = 0;
  long long r = n - 1;
  long long cnt = 1;
  long long f = 1;
  while (r > 0) {
    long long c = cnt * k;
    long long t = r - c;
    if (t <= 0) t = 0;
    ret += (sum[r] - sum[t]) * f;
    cnt *= k;
    f++;
    r = t;
  }
  return ret;
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    sum[0] = 0;
    sum[1] = a[1];
    for (int i = 2; i <= n; i++) {
      sum[i] = sum[i - 1] + a[i];
    }
    int m;
    scanf("%d", &m);
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < m; i++) {
      scanf("%d", &b[i]);
      if (ans[b[i]] == 0) ans[b[i]] = cal(b[i]);
    }
    for (int i = 0; i < m - 1; i++) {
      printf("%I64d ", ans[b[i]]);
    }
    printf("%I64d\n", ans[b[m - 1]]);
  }
  return 0;
}
