#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int x;
	cin >> x;
	while(x--){
		int n,k;
		cin >> n >> k;
		int a[n];
		vector<int> dist;
		for(int i=0;i<n;i++) cin >> a[i];
		if(n <= k){
			cout << 0 << endl;
			continue;
		}
		int ret = a[n-1] - a[0];
		for(int i=1;i<n;i++){
			dist.push_back(a[i] - a[i-1]);
		}
		
		sort(dist.begin(), dist.end(), greater<int>());
		for(int i=0;i<k-1;i++){
			ret -= dist[i];
		}
		cout << ret << endl;
	}
}