#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);
prefix[0]=v[0];
for(int i=1;i<=n;i++){
prefix[i]=prefix[i-1]+v[i];
}
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+azsKICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgY2luPj5pbjsKICAgICAgICAgICAgdi5wdXNoX2JhY2soaW4pOwogICAgICAgIH0KICAgICAgICBzb3J0KHYuYmVnaW4oKSx2LmVuZCgpKTsKCiAgICB2ZWN0b3I8bG9uZyBsb25nPnByZWZpeChuKzEsMCk7CiAgICAgICAgcHJlZml4WzBdPXZbMF07CiAgICAgICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgICAgICAgICBwcmVmaXhbaV09cHJlZml4W2ktMV0rdltpXTsKICAgICAgICB9CgogICAgdmVjdG9yPGxvbmcgbG9uZz4gcmVzdWx0KG4pOwogICAgICAgIGZvciAoaW50IG0gPSAxOyBtIDxuOyBtKyspIHsKICAgICAgICAgICAgaW50IGZyZWVfaXRlbXMgPSAobSAtIDEpIC8gKGsgKyAxKTsKICAgICAgICAgICAgaW50IHBhaWRfaXRlbXMgPSBtIC0gZnJlZV9pdGVtczsKICAgICAgICAgICAgcmVzdWx0W20gLSAxXSA9IHByZWZpeFtwYWlkX2l0ZW1zXTsKICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgY291dCA8PCByZXN1bHRbaV0gPDwgIiAiOwogICAgICAgIH0KICAgICAgICBjb3V0IDw8ICJcbiI7CgoKICAgICAgICAKCiAgICB9CgogICAgCgoKfQoKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUobnVsbHB0cik7CiAgICBzb2x2ZSgpOwogICAgcmV0dXJuIDA7Cn0=