#include <cstdio>
#include <iostream>
using namespace std;
	bool NotIn(long a, long* b){
		for (int q=0; q<1000; q++) {
			if (a==*(b+q)) return false;
		}
		return true;
	}
int main(){
	freopen("alibaba.in","r",stdin);
	long T, N, M, C[1000], D[1000], E[1000], max=-1001, mi=-1; long R=0; 
		for (int i=0; i<1000; i++) {C[i]=0;D[i]=0;E[i]=0;}
	cin>>T;
	for (int ni=0; ni<T; ni++){
		cin>>N>>M;
		for (int j=0; j<N; j++){
			cin>>C[j];}
				for (int j=0; j<M; j++){
		for (int i=0; i<N; i++){
			if ((C[i]>max)&&(NotIn(i,&E[0])))
			{max=C[i];mi=i;}
		}
		D[j]=max; E[j]=mi; max=-1001;
		}
		//sum c[]
		for (int l=0; l<N; l++) {R+=D[l];} 
		cout<<R<<"\n"; R=0;			for (int i=0; i<1000; i++) {C[i]=0;D[i]=0;E[i]=0;}
	}
	return 0;
}
