def solve():
import sys
input = sys.stdin.read
data = input().split()
t = int(data[0])
idx = 1
results = []
for _ in range(t):
n, k = map(int, data[idx:idx + 2])
idx += 2
costs = list(map(int, data[idx:idx + n]))
idx += n
# Sort the costs
costs.sort()
# Prefix sums for the sorted costs
prefix_sum = [0] * (n + 1)
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + costs[i - 1]
# Calculate minimum cost for buying m items
result = []
for m in range(1, n + 1):
# Calculate the number of items you need to pay for
free_items = (m - 1) // (k + 1)
paid_items = m - free_items
result.append(prefix_sum[paid_items])
results.append(" ".join(map(str, result)))
# Print all results
sys.stdout.write("\n".join(results) + "\n")
ZGVmIHNvbHZlKCk6CiAgICBpbXBvcnQgc3lzCiAgICBpbnB1dCA9IHN5cy5zdGRpbi5yZWFkCiAgICBkYXRhID0gaW5wdXQoKS5zcGxpdCgpCiAgICAKICAgIHQgPSBpbnQoZGF0YVswXSkKICAgIGlkeCA9IDEKICAgIHJlc3VsdHMgPSBbXQogICAgCiAgICBmb3IgXyBpbiByYW5nZSh0KToKICAgICAgICBuLCBrID0gbWFwKGludCwgZGF0YVtpZHg6aWR4ICsgMl0pCiAgICAgICAgaWR4ICs9IDIKICAgICAgICBjb3N0cyA9IGxpc3QobWFwKGludCwgZGF0YVtpZHg6aWR4ICsgbl0pKQogICAgICAgIGlkeCArPSBuCiAgICAgICAgCiAgICAgICAgIyBTb3J0IHRoZSBjb3N0cwogICAgICAgIGNvc3RzLnNvcnQoKQogICAgICAgIAogICAgICAgICMgUHJlZml4IHN1bXMgZm9yIHRoZSBzb3J0ZWQgY29zdHMKICAgICAgICBwcmVmaXhfc3VtID0gWzBdICogKG4gKyAxKQogICAgICAgIGZvciBpIGluIHJhbmdlKDEsIG4gKyAxKToKICAgICAgICAgICAgcHJlZml4X3N1bVtpXSA9IHByZWZpeF9zdW1baSAtIDFdICsgY29zdHNbaSAtIDFdCiAgICAgICAgCiAgICAgICAgIyBDYWxjdWxhdGUgbWluaW11bSBjb3N0IGZvciBidXlpbmcgbSBpdGVtcwogICAgICAgIHJlc3VsdCA9IFtdCiAgICAgICAgZm9yIG0gaW4gcmFuZ2UoMSwgbiArIDEpOgogICAgICAgICAgICAjIENhbGN1bGF0ZSB0aGUgbnVtYmVyIG9mIGl0ZW1zIHlvdSBuZWVkIHRvIHBheSBmb3IKICAgICAgICAgICAgZnJlZV9pdGVtcyA9IChtIC0gMSkgLy8gKGsgKyAxKQogICAgICAgICAgICBwYWlkX2l0ZW1zID0gbSAtIGZyZWVfaXRlbXMKICAgICAgICAgICAgcmVzdWx0LmFwcGVuZChwcmVmaXhfc3VtW3BhaWRfaXRlbXNdKQogICAgICAgIAogICAgICAgIHJlc3VsdHMuYXBwZW5kKCIgIi5qb2luKG1hcChzdHIsIHJlc3VsdCkpKQogICAgCiAgICAjIFByaW50IGFsbCByZXN1bHRzCiAgICBzeXMuc3Rkb3V0LndyaXRlKCJcbiIuam9pbihyZXN1bHRzKSArICJcbiIpCg==