#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = ({
    int x;
    scanf("%d", &x);
    x;
  });
  vector<long long int> a;
  for (int i = 0; i < n; i++) {
    long long int dummy;
    cin >> dummy;
    a.push_back(dummy);
  }
  sort((a).begin(), (a).end());
  long long int ans = 0;
  vector<long long int> b(100000, 0);
  vector<long long int> c(100001, 0);
  c[0] = 0;
  for (int i = 1; i < ((int)(a).size()); i++) c[i] = c[i - 1] + a[i - 1];
  int ct = 1;
  for (int i = ((int)(a).size()) - 2; i >= 0; i--) b[1] += ((ct++) * a[i]);
  int m = ({
    int x;
    scanf("%d", &x);
    x;
  });
  for (int i = 0; i < m; i++) {
    int ind = ({
      int x;
      scanf("%d", &x);
      x;
    });
    if (ind > 1 && b[ind] == 0) {
      ans = 0;
      int j = ((int)(a).size()) - 1;
      long long int p = ind;
      int cnt = 1;
      while (j >= 1) {
        int k = j - p;
        if (j < p) k = 0;
        ans += (cnt * (c[j] - c[k]));
        p = p * ind;
        j = k;
        cnt++;
      }
      b[ind] = ans;
    }
    cout << b[ind] << " ";
  }
  return 0;
}
