program ARMY;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var n,sm,i,a,i3,i2,e,s,s1,kp,ks:integer;
begin
assign (input,'ARMY.in');
reset(input);
readln(n);
s:=0;
for i:=1 to n do
 begin
 e:=0;
 s:=0;
 s1:=0;
   readln (ks,kp);
   for i2:=1 to kp do
 begin
   for i3:=1 to ks do
 begin
   read (s1);
    if s<s1 then s:=s1 else
 begin
   inc (e);

 end;
 s1:=0;
 end;
 end;
    writeln(e);

    

 end;
   { TODO -oUser -cConsole Main : Insert code here }
end.
 