#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f, N = 100005, M = 200005;
long long val[N], tim[N], vis[N], sum[N], ans[N];
int n, m;
int s[N], t[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> val[i];
  sort(val + 1, val + 1 + n);
  sum[0] = 0;
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + val[i];
  memset(ans, -1, sizeof(ans));
  cin >> m;
  while (m--) {
    long long a;
    cin >> a;
    if (~ans[a]) {
      cout << ans[a] << " ";
      continue;
    }
    ans[a] = 0;
    int now = n - 1;
    long long u = a, g = 1;
    while (1) {
      if (now <= u) {
        ans[a] += g * sum[now];
        s[g] = 1;
        t[g] = now;
        break;
      } else {
        ans[a] += g * (sum[now] - sum[now - u]);
        now -= u;
        g++;
        u *= a;
      }
    }
    cout << ans[a] << " ";
  }
}
