{ Depot - example solution
prog: depot
lang: pascal
}
const
  maxN=11;

type
  carr=array[1..maxN] of longint;

var
  i,j,k,r,n:longint;
  tbl:array[1..maxN,1..maxN] of longint;
  ntbl,order:array [1..maxN+1] of longint;
  fi, fo:text;

procedure display;
var i,j:longint;
begin
  for i:=1 to r do
  begin
    for j:=1 to ntbl[i] do
      write(tbl[i,j],' ');
    writeln;
  end;
end;

procedure recurse(nd:longint);
var
  i,j,k,l,v,t:longint ;
  str:string;
  strp:^string;
  c:carr;
begin
  if nd=n then
  begin
    str := ' ';
    for i:=n downto 1 do
    begin
      if i<n then write(fo,' ');
      write(fo,order[i]) ;
    end;
    writeln(fo) ;
    exit;
  end;

  for i:=1 to r do
  begin
    if ntbl[i]=0 then break;
    if ntbl[i]>ntbl[i+1] then
    begin

      v:=tbl[i,ntbl[i]];
      dec(ntbl[i]) ;
      for j:=i-1 downto 1 do
        for k:=ntbl[j] downto 1 do
          if v>tbl[j,k] then
          begin
            t := v;
            v:=tbl[j,k] ;
            tbl[j,k]:=t;
            c[j]:=k;
            break;
          end;

      order[nd+1]:=v;
      recurse(nd+1) ;

     for j :=1 to i-1 do
     begin
       t:=v ;
       v:=tbl[j,c[j]];
       tbl[j,c[j]]:=t;
     end;
     inc(ntbl[i]);
     tbl[i,ntbl[i]]:=v;

   end;
  end;
end;

begin
  assign(fi,'depot.in');
  assign(fo,'depot.out') ;
  reset(fi) ;
  read(fi,r) ;
  n:=0;
  for i:=1 to r do
  begin
    read(fi,ntbl[i]) ;
    inc(n,ntbl[i]);
    for j:=1 to ntbl[i] do
      read(fi,tbl[i,j]) ;
  end;
  close(fi);
  rewrite(fo) ;
  ntbl[r+1]:=0;
  recurse(0);
  close(fo);
end.

