#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int main(){
	int t,n,k,y,x,sum;
	cin>>t;
	while(t--){
		vector<int> in,box;
		sum=0;
		cin>>n>>k;
		for(int i=0;i<n;i++){
			cin>>x;
			box.push_back(x);
		}
		if(n<=k)
		cout<<0<<endl;
		else{
			for(int i=0;i<n-1;i++){
				in.push_back(box[i+1]-box[i]);
				sum+=in[i];
				
			}
			sort(in.begin(),in.end(),greater<int>());
			for(int i=0;i<k-1;i++){
			sum-=in[i];
			}
			cout<<sum<<endl;
		}
	}
	return 0;
}