{$APPTYPE CONSOLE}
var t,n,m,i,j,max,k,b,s:longint;
    a:array[1..1000] of integer;
begin
  assign(input, 'ALIBABA.IN'); reset(input);
  readln(t);
  for i:=1 to t do
   begin
   readln(n,m);
   s:=0;
   for j:=1 to n do
     read(a[j]);
   max:=0;
   for k:=1 to m do
    begin
    max:=0;
    for j:=1 to n do
     if a[j]>max then
      begin
      max:=a[j]; b:=j;
      end;
      if max>0 then begin
      s:=s+max; a[b]:=0;
      end;
    end;
   writeln(s);
   readln;
   end;
end.