#include <iostream>
#include <queue>

using namespace std;

long int t, n, m, ii, i, j, s;

int main(){
	freopen("ALIBABA.IN","r",stdin);
	cin >> t; 
	priority_queue <int> a;
	for (ii=0; ii<t; ii++){
		cin >>n>>m; s=0;
		for (i=0; i<n; i++){ cin >> j; if (j>=0) a.push(j); else a.push(0);}
		for (i=0; i<m; i++){ s+=(a.top()); a.pop();}
		cout << s << "\n";
		while(!a.empty()) a.pop();
		}
	return 0;
}