#include <bits/stdc++.h>
using namespace std;
int a[1000010];
long long sum[1000010];
map<int, long long> ans_ft;
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n, greater<int>());
  sum[0] = a[0];
  for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + a[i];
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int k;
    scanf("%d", &k);
    if (ans_ft.find(k) != ans_ft.end()) {
      cout << ans_ft[k] << endl;
    } else {
      long long idx = 0, t = k;
      int ft = 1;
      long long ans = 0;
      while (1) {
        if (idx + t >= n) {
          ans += (sum[n - 1] - sum[idx]) * ft;
          break;
        } else {
          ans += (sum[idx + t] - sum[idx]) * ft;
        }
        idx += t;
        t *= k;
        ++ft;
      }
      cout << ans << endl;
      ans_ft[k] = ans;
    }
  }
}
