#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
    int t; cin >> t;
    while(t-->0) {
        int n,x; cin >> n >> x;
        priority_queue<int> a;
        for(int i=0;i<n;++i) {
            int temp; cin >> temp;
            a.push(temp);
        }
        a.push(0);
        int result=0;
        while (1){
            int val=0; vector<int> b;
            for(int i=0;i<x;++i) {
                if(a.top()==0) break;
                val=a.top();
                b.push_back(val);
                a.pop();
            }
            if(val==0) break;
            result+=val;
            for(int k:b) {
                a.push(k-val);
            }
        }
        cout << result << "\n";
    }
	return 0;
}