#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> A(n);
  map<long long, long long> dp;
  for (long long i = (0); i < (n); i++) cin >> A[i];
  sort(A.begin(), A.end());
  vector<long long> sum(n);
  sum[0] = A[0];
  for (long long i = (1); i < (n); i++) sum[i] = sum[i - 1] + A[i];
  long long q;
  cin >> q;
  for (long long fd = (0); fd < (q); fd++) {
    long long k;
    cin >> k;
    if (!dp.count(k)) {
      long long ans = 0, a = 1, i = n - 2;
      while (i > -1) {
        ans += sum[i];
        a *= k;
        i -= a;
      }
      dp[k] = ans;
    }
    cout << dp[k] << " ";
  }
}
