#include<bits/stdc++.h>
using namespace std;
void solve(){
int t,n,k,in;
vector<int>v;
cin>>t;
while(t--){
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>in;
v.push_back(in);
}
sort(v.begin(),v.end());
vector<long long>prefix(n+1,0);
for(int i=1;i<=n;i++){
prefix[i]=prefix[i-1]+v[i-1];
}
vector<long long> result(n);
for (int m = 1; m <= n; m++) {
int free_items = (m - 1) / (k + 1);
int paid_items = m - free_items;
result[m - 1] = prefix[paid_items];
}
for (int i = 0; i < n; i++) {
cout << result[i] << " ";
}
cout << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHNvbHZlKCl7CiAgICBpbnQgdCxuLGssaW47CiAgICB2ZWN0b3I8aW50PnY7CiAgICBjaW4+PnQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIGNpbj4+bj4+azsKICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgY2luPj5pbjsKICAgICAgICAgICAgdi5wdXNoX2JhY2soaW4pOwogICAgICAgIH0KICAgICAgICBzb3J0KHYuYmVnaW4oKSx2LmVuZCgpKTsKCiAgICB2ZWN0b3I8bG9uZyBsb25nPnByZWZpeChuKzEsMCk7CgogICAgICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKXsKICAgICAgICAgICAgcHJlZml4W2ldPXByZWZpeFtpLTFdK3ZbaS0xXTsKICAgICAgICB9CgogICAgdmVjdG9yPGxvbmcgbG9uZz4gcmVzdWx0KG4pOwogICAgICAgIGZvciAoaW50IG0gPSAxOyBtIDw9IG47IG0rKykgewogICAgICAgICAgICBpbnQgZnJlZV9pdGVtcyA9IChtIC0gMSkgLyAoayArIDEpOwogICAgICAgICAgICBpbnQgcGFpZF9pdGVtcyA9IG0gLSBmcmVlX2l0ZW1zOwogICAgICAgICAgICByZXN1bHRbbSAtIDFdID0gcHJlZml4W3BhaWRfaXRlbXNdOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgICBjb3V0IDw8IHJlc3VsdFtpXSA8PCAiICI7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgIlxuIjsKCgogICAgICAgIAoKICAgIH0KCiAgICAKCgp9CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShudWxscHRyKTsKICAgIHNvbHZlKCk7CiAgICByZXR1cm4gMDsKfQ==