program game19;
type game15=array[1..4,1..4] of byte;
     shift1=(left,up,right,down);
     path2=array[1..1,left..down] of boolean;
     path1=^path2;
     zzz=array [1..65000] of shift1;

var cmdline1:string;
    start,final:game15;
    show,default:boolean;
    convtbl:array[left..down,1..2] of integer;
    curpath:^zzz;
    minlength:integer;

function good(i,j:integer):boolean;
  begin
    good:=(i>0)and(i<4)and(j>0)and(j<4);
  end;

procedure setasdefault;
var i,j:integer;
  begin
    for i:=1 to 4 do
      for j:=1 to 4 do
        final[i,j]:=(i-1)*4+j;
  end;
procedure writehelp;
  begin
    writeln('Params ...?');
    readln;
  end;
procedure writeerror;
  begin
    writeln('Error!');
  end;
procedure read1(st:string;a:game15);
var f:text;
    i,j:integer;
    b:char;
    c:array[1..4,1..4] of string;
  begin
    assign(f,st);
    reset(f);
    read(f,b);
    for i:=1 to 4 do
      for j:=1 to 4 do
        begin
          while (b>'9')and(b<'1')and(b<>'x') do read(f,b);
          c[i,j]:=b;
          read(f,b);
          if ((b<='9')and(b>='0')) then c[i,j]:=c[i,j]+b;
        end;
    close(f);
    for i:=1 to 4 do
      for j:=1 to 4 do
        if length(c[i,j])=1 then
          begin
            if c[i,j]='x' then a[i,j]:=16
              else a[i,j]:=ord(c[i,j,1])-48;
          end else
            if length(c[i,j])=2 then
              a[i,j]:=ord(c[i,j,1])*10+ord(c[i,j,2])-528;
  end;
procedure readstart(st:string);
  begin
    read1(st,start);
  end;
procedure readfinal(st:string);
  begin
    read1(st,final);
  end;

function readit:boolean;
var start,final:text;
    s1,s2:string;
    index,j:byte;
  begin
    readit:=true;
    index:=paramcount;
    case index of
      0: begin
           writehelp;
           readit:=false;
         end;
      1: begin
           readstart(paramstr(1));
           show:=false;
           setasdefault;
         end;
      2: begin
           readstart(paramstr(2));
           if paramstr(1)='-solve' then show:=false
             else
               begin
               if paramstr(1)='-show' then show:=true
               else
                 begin
                   writeerror;
                   writehelp;
                   readit:=false;
                 end;
               end;
           setasdefault;
         end;
      3: begin
           readstart(paramstr(2));
           readfinal(paramstr(3));
           if paramstr(1)='-solve' then show:=false
             else
             begin
             if paramstr(1)='-show' then show:=true
               else
                 begin
                   writeerror;
                   writehelp;
                   readit:=false;
                 end;
             end;
           default:=false;
         end;
       end;
  end;

function trytask:boolean;
var addi:array[1..16,1..2] of integer;
    i,j,k,l,stposx,stposy,finposx,finposy:integer;
    new1:record
           quantity:integer;
           arr:path1;
         end;
    i1:shift1;

  function nextstep:boolean;
    var i1:shift1;
        i:integer;
        flag:boolean;
    begin
      nextstep:=true;
      i:=new1.quantity;
      flag:=false;
      repeat
        if new1.arr^[i,down] then
            begin
              flag:=true;
              i1:=left;
              while not new1.arr^[i,i1] do inc(i1);
              new1.arr^[i,i1]:=false;
              curpath^[i]:=i1;
            end
              else
                for i1:=left to down do new1.arr^[i,i1]:=true;
        dec(i);
      until (flag) or (i=0);
      if i=0 then nextstep:=false;
    end;

  function iftrue:boolean;
    var  add2:game15;
         i,j,k:integer;
    begin
      iftrue:=true;
      add2:=start;
      i:=1;
      repeat
        for j:=1 to 4 do
          for k:=1 to 4 do
            if good(j+convtbl[curpath^[i],1],k+convtbl[curpath^[i],2]) then
              begin
                add2[j+convtbl[curpath^[i],1],k+convtbl[curpath^[i],2]]:=add2[j,k];
                add2[i,j]:=16;
              end
                else
                  iftrue:=false;
        inc(i);
      until (i=new1.quantity+1)or(not iftrue);
      for i:=1 to 4 do
        for j:=1 to 4 do
          if add2[i,j]<>final[i,j] then iftrue:=false;
    end;

  begin
    for i1:=left to down do
      begin
        convtbl[i1,1]:=0;
        convtbl[i1,2]:=0;
      end;
    convtbl[left,1]:=-1;
    convtbl[up,2]:=-1;
    convtbl[right,1]:=1;
    convtbl[down,2]:=1;
    for i:=1 to 4 do
      for j:=1 to 4 do
        for k:=1 to 4 do
          for l:=1 to 4 do
            if start[i,j]=final[k,l] then
              begin
                addi[start[i,j],1]:=k-i;
                addi[start[i,j],2]:=l-j;
                if start[i,j]=16 then
                  begin
                    stposx:=i;
                    stposy:=j;
                    finposx:=k;
                    finposy:=l;
                  end;
              end;
    minlength:=-1;
    for i:=1 to 15 do
      minlength:=minlength+abs(addi[i,1])+abs(addi[i,2]);
    if odd(minlength)=odd(abs(addi[16,1])+abs(addi[16,2])) then
      begin
        getmem(new1.arr,65000);
        repeat
          inc(minlength);
          new1.quantity:=minlength;
          for i:=1 to minlength do
            for i1:=left to down do
              new1.arr^[i,i1]:=true;

          while (nextstep) and (iftrue) do;
        until iftrue;
        trytask:=true;
      end
        else trytask:=false;
  end;

procedure showresults;
var i:integer;
  begin
    if trytask then
      begin
        writeln(minlength);
        for i:=1 to minlength do
          case curpath^[i] of
            left:writeln('left');
            up:writeln('up');
            right:writeln('right');
            down:writeln('down');
          end;
      end
        else
          begin
            writeln('There are no solution!');
            readln;
          end;
  end;

begin
  getmem(curpath,65000);

  if readit then
    showresults;

end.