const
  edge:array[1..12,1..5]of byte
      =((2,3,4,5,6),(6,7,11,3,1),(2,11,10,4,1),(3,10,9,5,1),(4,9,8,6,1),(5,8,7,2,1),
        (6,8,12,11,2),(7,6,5,9,12),(8,5,4,10,12),(9,4,3,11,12),(10,3,2,7,12),(7,8,9,10,11));
  c:array[1..12,0..5]of byte
   =((0,0,0,0,0,0),(1,5,0,0,0,0),(2,1,5,0,0,0),(2,1,5,0,0,0),(2,1,5,0,0,0),(3,1,4,5,0,0),
     (3,1,3,5,0,0),(4,1,2,3,5,0),(4,1,2,3,5,0),(4,1,2,3,5,0),(5,1,2,3,4,5),(0,0,0,0,0,0));
  order:array[1..12]of byte=(1,2,3,4,5,6,12,7,8,9,10,11);
  inputfile='ball.in';
  outputfile='ball.out';
var
  tile:array[1..12,1..5]of byte;
  num:array[1..12,1..12]of byte;
  used:array[1..12]of boolean;
  n,t:array[1..12]of byte;
  i:byte;
function check(no,t,d:byte):boolean;
  var i:byte;
  begin
    check:=false;
    for i:=1 to c[no,0] do
      if tile[t,(c[no,i]+5-d) mod 5 + 1]<>num[no,edge[no,c[no,i]]]
      then exit;
    check:=true;
  end;
procedure run(lev:byte);
  var i,j,k:byte;
  begin
    if lev>12 then begin
       for i:=1 to 12 do writeln(t[i],' ',n[i]);
       close(output);
       halt;
    end;
    for i:=2 to 12 do
      if not used[i] then
         for j:=1 to 5 do
           if check(order[lev],i,j) then begin
              n[order[lev]]:=edge[order[lev],j];
              t[order[lev]]:=i;
              used[i]:=true;
              for k:=0 to 4 do begin
                num[order[lev],edge[order[lev],(j+k-1) mod 5 + 1]]:=tile[i,k+1];
                num[edge[order[lev],(j+k-1) mod 5 + 1],order[lev]]:=tile[i,k+1];
              end;
              run(lev+1);
              used[i]:=false;
           end;
  end;
begin
  assign(input,inputfile);
  reset(input);
  for i:=1 to 12 do readln(tile[i,1],tile[i,2],tile[i,3],tile[i,4],tile[i,5]);
  close(input);
  fillchar(used,sizeof(used),0);
  used[1]:=true;
  n[1]:=2;
  t[1]:=1;
  for i:=1 to 5 do begin
    num[edge[1,i],1]:=tile[1,i];
    num[1,edge[1,i]]:=tile[1,i];
  end;
  assign(output,outputfile);
  rewrite(output);
  run(2);
  writeln(-1);
  close(output);
end.

