program code(input,output);
var
a:array[0..110]of integer;
b:array[0..110]of integer;
c:array[0..110]of integer;
i,j,l,m,n,s:integer;
f1,f2:text;
procedure del(x:byte);
var
i:integer;
begin
for i:=x to n-2 do
c[i]:=c[i+1];
end;
begin
assign(f1,'code.in');
reset(f1);
assign(f2,'code.out');
rewrite(f2);
readln(f1,m,n);
for l:=1 to m do
begin
readln(f1,s);
for i:=0 to n-1 do
read(f1,a[i]);
if s=1 then
begin
b[0]:=0;
i:=1;
while i<=n-1 do
begin
b[i]:=0;
for j:=0 to i-1 do
if a[j]<a[i] then
inc(b[i]);
inc(i);
end;
for i:=0 to n-2 do
write(f2,b[i],' ');
writeln(f2,b[n-1]);
end
else
begin
for j:=0 to n-1 do
c[j]:=j;
for i:=n-1 downto 0 do
begin
b[i]:=c[a[i]];
del(a[i]);
end;
for i:=0 to n-2 do
write(f2,b[i],' ');
writeln(f2,b[n-1]);
end;
end;
close(f1);
close(f2);
end.