program ARMY;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var x:array[1..10000] of integer;
  n,c,a,b,s,k,d:integer;
  m:byte;
  begin
  {assign(input,'ARMY.IN');}
  read(k);
  read(n);
  read(m);
  s:=0;
  for a:=1 to k do
   begin

    for c:=1 to m do
         begin
      for b:=1 to n do read(x[b]);
            for d:=1 to (n-1) do if (x[d]>x[d+1]) then s:=(s+1);
     end;
     writeln(s+1);
     s:=0;
   end;
 read(a);


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