#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}


int main(void) {
	int N,i,j;
	scanf("%d", &N);
	int n, k,distance;
	int house[100000];
	for (i = 0; i < N; i++) {
		scanf("%d %d", &n, &k);
		for (j = 0; j < n; j++) {
			scanf("%d", &house[j]);
		}
		distance = house[n - 1] - house[0];
		for (j = 0; j < n - 1; j++) {
			house[j] = house[j + 1] - house[j];
			
		}
		qsort(house, n - 1, sizeof(int), compare_int);
		for (j = 0; j < k-1; j++) {
			distance -= house[n - 2 - j];
		}
		if (n <= k)distance = 0;
		printf("%d\n", distance);
	}
	return 0;
}