#include <bits/stdc++.h>
using namespace std;
pair<long long, int> solve(int v[], int sz, int slope) {
// menghitung DP
long long dp[sz+1];
dp[0]=0;
dp[1]=min(0,v[1]-slope);
for(int temp=2;temp<sz;temp++) dp[temp]=min(dp[temp-1],dp[temp-2]+v[temp]-slope);
// backtracking untuk mencari tahu minimum bilangan yang diambil
long long opt=dp[sz-1];
int pos=sz-1,cnt=0;
while(pos>0)
{
if(dp[pos]==dp[pos-1]) pos--;
else pos-=2,cnt++;
}
return {opt, cnt};
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int tc;
cin>>tc;
while(tc--) {
int n,k;
cin>>n>>k;
int a[n],temp;
int v[n];
v[0]=0;
for(temp=0;temp<n;temp++) {
cin>>a[temp];
if(temp>0) v[temp]=(a[temp]-a[temp-1]);
}
int left=0,right=1000000000,mid;
long long gval,slope;
int sz=n;
while(left<=right) {
mid=(left+right)/2;
// mencari G optimal dan banyaknya bilangan minimum
pair<long long, int> ins = solve(v, sz, mid);
long long opt=ins.first;
int cnt=ins.second;
if(cnt<=k) {
slope=mid;
gval=opt;
left=mid+1;
}
else right=mid-1;
}
cout<<gval+k*slope<<"\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpwYWlyPGxvbmcgbG9uZywgaW50PiBzb2x2ZShpbnQgdltdLCBpbnQgc3osIGludCBzbG9wZSkgewoKCS8vIG1lbmdoaXR1bmcgRFAKCWxvbmcgbG9uZyBkcFtzeisxXTsKCWRwWzBdPTA7CglkcFsxXT1taW4oMCx2WzFdLXNsb3BlKTsKCWZvcihpbnQgdGVtcD0yO3RlbXA8c3o7dGVtcCsrKQlkcFt0ZW1wXT1taW4oZHBbdGVtcC0xXSxkcFt0ZW1wLTJdK3ZbdGVtcF0tc2xvcGUpOwoKCS8vIGJhY2t0cmFja2luZyB1bnR1ayBtZW5jYXJpIHRhaHUgbWluaW11bSBiaWxhbmdhbiB5YW5nIGRpYW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