program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
M,N, t, k, i, s, j, d : integer;
f1 : text;
m1 : array[1..1000] of integer;
begin
Assign(f1, 'ALIBABA.IN');
reset(f1);
readln(f1, t);
for k := 1 to t do begin
  Readln(f1, n, m);
  for I := 1 to n do begin
    Read(f1, m1[i]);
  end;
  S := 0;
  while s = 0 do begin
    s := 1;
    for j := 1 to n-1 do begin
      if m1[j] < m1[j+1] then begin
         s := 0;
         d := m1[j];
         m1[j] := m1[j+1];
         m1[j+1] := d;
       end;
     end;
   end;
   d := 0;
   for j := 1 to m do begin
      if m1[j] < 0 then break else

      d:= d+ m1[j];
     end;
    writeln(d);
end;




end.
