program code;
var
s,t,m,k,n,i,j:longint;
a,b:array[1..100]of longint;
bz:array[0..99]of boolean;
begin
assign (input,'code.in');
reset (input);
assign (output,'code.out');
rewrite (output);
readln (m,n);
for k:=1 to m do
begin
readln (s);
for i:=1 to n do
read (a[i]);
readln;
if s=1 then
begin
for i:=1 to n do
begin
t:=0;
for j:=1 to i-1 do
begin
if a[j]<a[i] then
inc(t)
end;
write (t,' ')
end;
writeln
end
else
begin
for i:=0 to n-1 do
bz[i]:=true;
for i:=n downto 1 do
begin
t:=0;
for j:=0 to n-1 do
if bz[j] then
begin
inc(t);
if t=a[i]+1 then
begin
bz[j]:=false;
b[i]:=j
end
end
end;
for i:=1 to n do
write (b[i],' ');
writeln
end
end;
close (input);
close (output)
end.