#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <assert.h>

using namespace std;

int r(int max)
{
	int r;
	do
	{
		r = rand()%max;
	}
	while(r < 1);
	return r;
}

void generate_cost(int n)
{
	for(int i=0; i<n; i++)
	{
		int c;
		c = r(1000000);
		assert(1 <= c && c <= 1000*1000);
		
		cout << c;
		if (i!= n-1) cout << " ";			
	}
	cout << endl;
}

void generate_tests(int test)
{
	cout << test << endl;

	int n, k;

	cout << 3 << " " << 3 << endl;
	cout << 2 << " " << 5 << " " << 6 << endl;

	n = 1, k = 1;
	cout << n << " " << k << endl;
	cout << 1 << endl;
	
	n = 1, k = 100;
	cout << n << " " << k << endl;
	cout << 1000000 << endl;

	for(int t=0; t<test-6; t++)
	{
		int n, k;
		n = r(100);
		k = r(100);

		assert(1 <= n && n <=100);
		assert(1 <= k && k <=100);

		cout << n << " " << k << endl;
		generate_cost(n);	
		
	}

	n = 100, k = 1;
	cout << n << " " << k << endl;
	generate_cost(n);

	n = 100, k = 100;
	cout << n << " " << k << endl;
	generate_cost(n);

	n = 100, k = 1;
	cout << n << " " << k << endl;
	for(int i=0; i<n; i++)
	{
		cout << 1000000;
		if (i<n) cout << " ";
	}
	cout << endl;

}



int main()
{
	freopen("economies.in", "r", stdin);
	//freopen("economies.out", "w", stdout);
	
	//generate_tests(30);
	//return 0;

	int test;
	cin >> test;
	for(int t=0; t<test; t++)
	{
		int n, k;
		cin >> n >> k;

		assert(1 <= n && n <=100);
		assert(1 <= k && k <=100);

		int c[128];
		for(int i=0; i<n; i++)
		{
			cin >> c[i];
			assert(1 <= c[i] && c[i] <= 1000*1000);
		}

		sort(c, c+n, greater<int>());

		long long res = 0;
		int mult = 1, cnt = 0;

		for(int i=0; i<n; i++)
		{
			res += mult*c[i];
			cnt++;
			if (cnt == k)
			{
				cnt = 0;
				mult++;
			}
		}

		cout << res << endl;

	}

	return 0;
}

