#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
map<int, long long> kk;
bool Cmp(const long long a, const long long b) { return a > b; }
int main() {
  long long k, q, n, number, ans, height, itr;
  while (cin >> n) {
    a.clear();
    for (int i = 0; i < n; i++) {
      cin >> number;
      a.push_back(number);
    }
    sort(a.begin(), a.end(), Cmp);
    for (int i = 0; i < a.size(); i++) {
      if (i) a[i] += a[i - 1];
    }
    cin >> q;
    for (int j = 0; j < q; j++) {
      cin >> number;
      if (kk.find(number) != kk.end())
        cout << kk[number] << " ";
      else {
        ans = 0;
        height = 1;
        k = number;
        itr = 0;
        while (itr < a.size()) {
          ans += ((a[((k + itr > a.size() - 1) ? (a.size() - 1) : (k + itr))] -
                   a[itr]) *
                  height);
          itr += k;
          height++;
          k *= number;
        }
        kk[number] = ans;
        cout << ans << " ";
      }
    }
    cout << endl;
  }
}
