const
maxbr=50;
maxk=1000;
var
 b:array[1..maxk] of string[20];
 a:array[1..19] of integer;
 c:array[1..maxbr,1..maxbr] of integer;
 fl:array[1..maxbr,1..maxbr] of boolean;
 f,fo,ff:text;
 j,i,k,l,n,br:integer;
 s:string;
 procedure perm(i:integer);
  var  k,l:integer;
  begin
  if i=0 then begin
      for l:=1 to n do write(f,a[l]);
      writeln(f); br:=br+1;
     end else
   for k:=0 to 1 do begin
    a[i]:=k; perm(i-1);
   {  for l:=1 to n do
      write(f,a[l]);
      writeln(f) }
   end;
 end;

begin
 br:=0;
 assign(f,'f.o');
 assign(fo,'fo.o');
 rewrite(f);
 rewrite(fo);
 n:=4;

 for i:=1 to n do c[i,1]:=0;
 for i:=1 to n do
  for j:=1 to n do fl[i,j]:=false;

 perm(n);
 writeln(f,br);
 close(f);
 reset(f);
 for i:=1 to br do begin
  readln(f,s);
  for k:=1 to n do begin
   for l:=1 to n do
    if l<>k then write(fo,s[l]);
   writeln(fo);
  end;
 end;

close(f);
close(fo);

reset(fo);

 for i:=1 to br*n do read(fo,b[i]);

 for i:=1 to br-1 do
  for j:=i+1 to br do begin
   k:=i*n;
   l:=j*n;
   while (k<(i+1)*n+1) and (fl[i,j]=false) do begin
    while (l<(j+1)*n+1) and (fl[i,j]=false) do begin
      if b[k]=b[l] then begin fl[i,j]:=true; fl[j,i]:=true;
       c[i,1]:=c[i,1]+1; c[i,c[i,1]+1]:=j;
       c[j,i]:=c[j,1]+1; c[j,c[j,1]+1]:=i;
      end;
      l:=l+1;
      end;
      k:=k+1;
      end;
      end;

  for i:=1 to br do begin
   for j:=1 to br do
    write(c[i,j],' ' );
   writeln;
   end;
end.
