program ALIBABA;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
a:array[1..1001] of integer;
i,j,k,n,m,t,max,c,s:integer;
begin
reset(input,'ALIBABA.IN');
//rewrite(output,'output.txt');

readln(t);
for i := 1 to t do begin

 readln(n,m);

 fillchar(a,sizeof(a),0);

 for j := 1 to n do
  read(a[j]);
    s:=0;
   for j := 1 to m do begin
    max:=-1001;

   for k := 1 to n do
    if max<a[k] then begin
      max:=a[k]; c:=k; end;
    
      a[c]:=-1005; s:=s+max;
    end;

 { max:=-1005;

  for j := 1 to m do begin


    for k := 1 to n do begin
      if a[k]>=max then max:=a[k];
      c:=k;
    end;

     a[c]:=-1004; s:=s+max;
    max:=-1005;

  end;
       }
     writeln(s);
end;

end.
