#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 100;
long long a[N], sum[N], ans[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(ans, -1, sizeof(ans));
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, greater<long long>());
  sum[n - 1] = a[n - 1];
  for (long long i = n - 2; i >= 0; i--) {
    sum[i] = a[i] + sum[i + 1];
  }
  long long q;
  cin >> q;
  for (long long _ = 0, x; _ < q; _++) {
    cin >> x;
    if (ans[x] != -1) {
      cout << ans[x] << " ";
      continue;
    }
    ans[x] = 0;
    long long tmp = x, i = 1;
    while (i < n) {
      ans[x] += sum[i];
      i += tmp;
      tmp *= x;
    }
    cout << ans[x] << " ";
  }
  cout << "\n";
  return 0;
}
