#include <algorithm>
#include <iostream>
using namespace std;
int T,k,n,a[100000 + 10],delta[100000 + 10];
int main(){
	cin >> T ;
	for (int t = 0; t < T ; ++t){
		cin >> n >> k ;
		for (int i = 0; i < n ; ++i )cin >> a[i];
		if(n>k){
			for (int l = 0 ; l + 1 < n  ; ++l ) delta[l] = a[l+1] - a[l];
			sort(delta,delta+n-1);
			int length = a[n-1] - a[0];
			for(int m = 0 ; m + 1 < k ; ++m)length = length - delta[n-m-2];
			cout << length << endl;
		}
		else cout << 0 << endl;
	}
return 0;
}