program dd; var cisla : array[0..9] of string; line : string; a,b,c,d, i,j,k,l,p : byte; possible: array[1..4,0..9] of boolean; posunuti: array[1..4] of integer; count:array[1..4] of integer; ids: array[1..4] of byte; ambigous: boolean; begin cisla[0] := '+---+| || |+ +| || |+---+'; cisla[1] := ' + | | + | | +'; cisla[2] := '+---+ | |+---+| | +---+'; cisla[3] := '+---+ | |+---+ | |+---+'; cisla[4] := '+ +| || |+---+ | | +'; cisla[5] := '+---+| | +---+ | |+---+'; cisla[6] := '+---+| | +---+| || |+---+'; cisla[7] := '+---+ | | + | | +'; cisla[8] := '+---+| || |+---+| || |+---+'; cisla[9] := '+---+| || |+---+ | |+---+'; posunuti[1]:=0; posunuti[2]:=2; posunuti[3]:=7; posunuti[4]:=9; readln(line); while(line <> 'end') do begin for i:=1 to 4 do for j:=0 to 9 do possible[i,j]:=true; for i:=1 to 7 do begin for j:=1 to 4 do begin for k:=0 to 4 do begin p:=(j-1)*5+posunuti[j] + k+1; for l:=0 to 9 do begin if((line[p] <> '.') and(line[p] <> cisla[l][(i-1)*5+k+1]))then begin {writeln('Chyba', i,' ',j,' ',k,' ',l);} possible[j,l]:=false; end; end; end; end; readln(line); end; ambigous:=false; {for i:=1 to 4 do begin count[i]:=0; for j:=1 to 9 do begin if(possible[i,j])then begin inc(count[i]);ids[i]:=j;end; end; if(count[i] > 1) then ambigous := true; end;} count[1]:=0;count[4]:=0;count[3]:=0;count[2]:=0; for i:=0 to 1 do begin if(possible[1,i])then begin inc(count[1]);ids[1]:=i;end; end; if(possible[1,2])then begin for j:= 0 to 3 do if(possible[2,j])then begin inc(count[1]); ids[1]:=2; end; end; if(count[1] > 1 ) then ambigous:=true; if(ids[1] = 2)then begin for i:= 0 to 3 do begin if(possible[2,i])then begin inc(count[2]);ids[2]:=i;end; end; end else begin for i:= 0 to 9 do begin if(possible[2,i])then begin inc(count[2]);ids[2]:=i;end; end; end; if(count[2] > 1 ) then ambigous:=true; for i:=0 to 5 do begin if(possible[3,i])then begin inc(count[3]);ids[3]:=i;end; end; if(count[3] > 1 ) then ambigous:=true; for i:= 0 to 9 do begin if(possible[4,i])then begin inc(count[4]);ids[4]:=i;end; end; if(count[4] > 1 ) then ambigous:=true; if(ambigous)then writeln('ambiguous') else begin writeln(ids[1],ids[2],':',ids[3],ids[4]); end; readln;readln(line); end; writeln('end'); end.