#include <stdio.h>
#include <iostream>
using namespace std;
int main ()
{
freopen("ALIBABA.in","r",stdin);
int t;
cin >> t;
for (int k=0; k < t; k++)
{
    int n, m;
	cin >> n >> m;
	int a[1010];
	for (int i=0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] < 0) a[i] = 0;
	}
	int b = 1;
	while (b==1)
	{
		b=2;
		for (int i=0; i < n -1; i++)
		{
			if (a[i] < a[i+1])
			{
				int tmp=a[i];
				a[i] = a[i+1];
				a[i+1] = tmp;
				b=1;
			}
		}
	}
	long sum=0;
	for (int i=0; i < m; i++)
	{
         sum += a[i];
	}
	cout << sum << endl;
}
}