uses math;

Var tc,i,n,m,t,r,mindeg,maxdeg:longint;
    can:array[0..123,0..123]of boolean;
    unique:array[0..123]of boolean;
    uk:longint;
    w:array[0..123,0..123]of boolean;
    flag:boolean;
    e:array[0..103]of longint;
    a:array[0..103,0..103]of longint;
    p:array[0..123]of longint;
  procedure gen_random_permutation(n:longint);
   var i,tmp,x:longint;
     begin
       for i:=1 to n do
         p[i]:=i;
       for i:=1 to n do
         begin
           x:=random(i)+1;
           tmp:=p[x];
           p[x]:=p[i];
           p[i]:=tmp;
         end;
     end;
 procedure swap(var x,y:longint);
   var tmp:longint;
     begin
       tmp:=x;
       x:=y;
       y:=tmp;
     end;
 procedure genFile;
   var i,j:longint;
       s:string;
     begin
       inc(tc);
       str(tc,s);
       if length(s)=1 then s:='0'+s;
       assign(output,s);
       rewrite(output);
       Writeln(n,' ',m,' ',t,' ',r);
       gen_random_permutation(m);
       for i:=1 to n do
         begin
           Write(e[i]);
           for j:=1 to e[i] do
             Write(' ',p[a[i,j]]);
           Writeln;
         end;
       close(output);
     end;
 function get_random_on_range(l,r:longint):longint;
     begin
       get_random_on_range:=random(r-l+1)+l;
     end;
 procedure genrand;
  var i,j,deg,x:longint;
    begin
      fillchar(e,sizeof(e),0);
      fillchar(can,sizeof(can),false);
      fillchar(unique,sizeof(unique),false);
      fillchar(w,sizeof(w),false);
      if flag then
        begin
          gen_random_permutation(m);
          for i:=1 to min(m,uk) do
            begin
              x:=random(n)+1;
              w[x,p[i]]:=true;
              unique[p[i]]:=true;
            end;
        end;
      for i:=1 to n do
        begin
          deg:=get_random_on_range(mindeg,maxdeg);
          deg:=min(deg,m);
          e[i]:=deg;
          gen_random_permutation(m);
          for j:=1 to deg do
           begin
             a[i,j]:=p[j];
             can[i,p[j]]:=true;
           end;
          j:=1;
          while j<=e[i] do
            begin
              if (unique[a[i,j]])and(w[i,a[i,j]]=false) then
                begin
                  can[i,a[i,j]]:=false;
                  swap(a[i,e[i]],a[i,j]);
                  dec(e[i]);
                end
                else inc(j);
            end;
        end;
    end; 
 begin
    tc:=-1;
//    randseed:=7447747;
randomize();
{    n:=5;
    m:=5;
    t:=1;
    r:=1;
    flag:=false;
    for i:=1 to 10 do
      begin
        mindeg:=0;
        maxdeg:=2;
        genrand;
        genfile;
      end;       }
//    for i:=1 to 10000 do
  //    begin
        n:=random(5)+1;
        m:=random(5)+1;
        t:=random(10)+1;
        r:=t div (random(2)+1);
        mindeg:=random(n);
        maxdeg:=random(n);
        if mindeg>maxdeg then swap(mindeg,maxdeg);
        genrand;
        genfile;
    //  end;
{    for i:=1 to 10 do
      begin
        n:=100;
        m:=100;
        t:=random(10000)+1;
        r:=1;
        mindeg:=random(10);
        maxdeg:=random(10);
        if mindeg>maxdeg then swap(mindeg,maxdeg);
        genrand;
        genfile;
      end;
    flag:=true;
    for i:=1 to 30 do
      begin
        n:=100;
        m:=100;
        t:=random(10000)+1;
        r:=t div (random(10)+1);
        mindeg:=random(10);
        uk:=i;
        maxdeg:=random(100);
        if mindeg>maxdeg then swap(mindeg,maxdeg);
        genrand;
        genfile;
      end;
   }

  end.
