program Project1;

{$APPTYPE CONSOLE}

procedure qsort(var a:array of integer);
   procedure sort(l,r:integer);
     var i,j,x,y:integer;
   begin
   i:=L;
   j:=r;
   x:=a[(l+r)div 2];
   repeat
     while a[i] < x do inc(i);
     while x < a[j] do dec(j);
     if not (i>j) then
      begin
        y:=a[i];
        a[i]:=a[j];
        a[j]:=y;
        inc(i);
        dec(j);
      end;
     until I>j;
     if l<j then sort (l,j);
     if i<r then sort (I,r);
   end;

begin
 sort(0,high(a));
end;

var
f:textfile;
n,m,ii,jj,t,s:integer;
a1:array of integer;
begin
assign(f, 'ALIBABA.IN');
reset(f);
readln(f,t);
for jj := 1 to t do begin
readln(f,n,m);
setlength(a1,n);
for ii := 0 to n - 1 do begin
  read(f,a1[ii]);
end;
qsort(a1);
s:=0;
{for ii := 0 to n - 1 do begin
  WRITELN(II,' ',A1[II]);
end;}
for ii := N-1 downto n-m do begin

    if a1[ii]>0 then begin
        s:=s+a1[ii];
    end;
end;
writeln(s);
//writeln('---');
end;
close(f);
end.

