#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+azsKICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgY2luPj5pbjsKICAgICAgICAgICAgdi5wdXNoX2JhY2soaW4pOwogICAgICAgIH0KICAgICAgICBzb3J0KHYuYmVnaW4oKSx2LmVuZCgpKTsKCiAgICB2ZWN0b3I8bG9uZyBsb25nPnByZWZpeChuKzEsMCk7CiAgICAgICAgcHJlZml4WzBdPXZbMF07CiAgICAgICAgZm9yKGludCBpPTE7aTxuO2krKyl7CiAgICAgICAgICAgIHByZWZpeFtpXT1wcmVmaXhbaS0xXSt2W2ldOwogICAgICAgIH0KCiAgICB2ZWN0b3I8bG9uZyBsb25nPiByZXN1bHQobik7CiAgICAgICAgZm9yIChpbnQgbSA9IDE7IG0gPD0gbjsgbSsrKSB7CiAgICAgICAgICAgIGludCBmcmVlX2l0ZW1zID0gKG0gLSAxKSAvIChrICsgMSk7CiAgICAgICAgICAgIGludCBwYWlkX2l0ZW1zID0gbSAtIGZyZWVfaXRlbXM7CiAgICAgICAgICAgIHJlc3VsdFttIC0gMV0gPSBwcmVmaXhbcGFpZF9pdGVtc107CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGNvdXQgPDwgcmVzdWx0W2ldIDw8ICIgIjsKICAgICAgICB9CiAgICAgICAgY291dCA8PCAiXG4iOwoKCiAgICAgICAgCgogICAgfQoKICAgIAoKCn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgc29sdmUoKTsKICAgIHJldHVybiAwOwp9