#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long sum[N];
int num[N];
long long ans[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  sort(num + 1, num + n + 1);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + num[i];
  int m, k;
  cin >> m;
  memset(ans, -1, sizeof(ans));
  while (m--) {
    scanf("%d", &k);
    long long &t = ans[k];
    if (t == -1) {
      t = 0;
      int cnt = 1;
      long long x = k;
      for (int i = n - 1; i >= 1; cnt++) {
        int s = max(i - x, 0LL);
        x *= k;
        t += cnt * (sum[i] - sum[s]);
        i = s;
      }
    }
    cout << t << " ";
  }
}
