#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[1000001];
long long f[1000001];
long long s[1000001];
long long q;
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%lld", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) f[i] = f[i - 1] + a[i];
  for (int i = 1; i <= 100000; ++i) {
    long long res = 0;
    long long x = i;
    for (long long j = n - 1; j >= 1; j -= x, x *= i) {
      res += f[j];
    }
    s[i] = res;
  }
  scanf("%lld", &q);
  for (int i = 1; i <= q; ++i) {
    long long x;
    scanf("%lld", &x);
    printf("%lld\n", s[x]);
  }
}
