(*
 * II Всероссийская Командная Олимпиада Школьников по Программированию
 *
 * Задача:      Электронные Часы
 * Автор:       С. Е. Столяр
 * Решение:     Андрей Станкевич
 *)
 
program electronic_clock;

type
    tdigit = array [1..6, 1..5] of char;
    
function check(a, b: tdigit): boolean;
var
    i, j: longint;
begin
    check := false;
    for i := 1 to 6 do
        for j := 1 to 5 do
            if (a[i][j] = '.') and (b[i][j] = '#') then
                exit;
    check := true;
end;

var
    can: array [1..4, 0..9] of boolean;
    a: array [0..9] of tdigit;
    b: array [1..4] of tdigit;
    i, j, k: longint;
    ch, cm, hh, mm: longint;

begin
    assign(input, 'digits.txt');
    reset(input);
    
    for i := 1 to 6 do
    begin
        for j := 0 to 9 do
            for k := 1 to 5 do
                read(a[j][i][k]);
        readln;
    end;
                
    close(input);
    
{    assign(input, 'input.txt');
    reset(input);
    assign(output, 'output.txt');
    rewrite(output);}

    for i := 1 to 6 do
    begin
        for j := 1 to 4 do
            for k := 1 to 5 do
                read(b[j][i][k]);
        readln;
    end;
    
    for i := 0 to 9 do
        for j := 1 to 4 do
            can[j][i] := check(a[i], b[j]);
            
    ch := 0;
    for i := 0 to 23 do
    begin
        if can[1][i div 10] and can[2][i mod 10] then
        begin
            inc(ch);
            hh := i;
{            writeln('hh ', hh);}
        end;
    end;

    cm := 0;
    for i := 0 to 59 do
    begin
        if can[3][i div 10] and can[4][i mod 10] then
        begin
            inc(cm);
            mm := i;
{            writeln('mm ', mm);}
        end;
    end;
    
    if (ch = 0) or (cm = 0) then
    begin
        writeln('ERROR');
    end 
    else if (ch = 1) and (cm = 1) then 
    begin
        writeln(hh div 10, hh mod 10, ':', mm div 10, mm mod 10);
    end else begin
        writeln('AMBIGUITY');
    end;

    
    close(input);
    close(output);
end.
