var
k,p,t,i,j,n,m: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);
for j:=1 to n do
read (a[j]);
readln;
j:=1;
while j<n do begin
if a[j]>a[j+1] then begin
p:=a[j];
a[j]:=a[j+1];
a[j+1]:=p;
if j>1 then dec (j,2);
end;
inc (j);
end;
k:=0;
for j:=n downto n-m+1 do
if a[j]>0 then k:=k+a[j];
writeln (k);
end;
end.