program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;

var
  a,b: array[1..100] of integer;
  x,o,y,n,m,i,j: integer;
  s: string;
  f: textfile;
begin
y:=0;
AssignFile(f,'army.in');
reset(f);
readln(f,s);
x:=strtoint(s);
for o:=1 to x do begin
read(f,n);
read(f,m);
if (n<=10000) and (m<=100) then begin
for j:=1 to m do begin
  for i:=1 to n do read(f,a[i]);
  for i:=2 to n do begin
    if a[i]-a[i-1]<>1 then y:=y+1;
  end;
end;
end else break;
b[o]:=y;
y:=0;
end;
for i:=1 to x do begin
s:=inttostr(b[i]);
writeln(s);
end;
closefile(f);
end.
