program ALIBABA;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var s,n,m,t,j,i1,i2,max,i:longint;
c: array [1..1000] of longint;
begin
assign (input, 'ALIBABA.in');
reset (input);
read (t);
for i1:=1 to t do
  begin
  read (n,m);
  for i:=1 to n do
    read (c[i]);
    s:=0;j:=0;

max:=c[1];
for i:=1 to n do
  begin
    if (max<c[i]) and (c[i]>0)
    then
     begin
    max:=c[i];


  j:=j+1;
  if j<=m then
begin
  s:=s+max;
c[i]:=0; end;   end;
end;writeln(s);  end;



end.
