import java.io.*;
import java.lang.*;
import java.util.*;

public class cc {
 

  public static void main(String[] args) throws IOException {

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    String line;
    
    

    outer : while (true) {

      line = reader.readLine();
      if ("end".equals(line)) {
	 System.out.println("end");
	 return;
      }     

      // parametry na radku
      // String[] params = line.split("\\s");
      
//      int hh = toInt(""+line.charAt(0));
 //     int hl = toInt(""+line.charAt(1));
  //    int mh = toInt(""+line.charAt(3));
  //    int ml = toInt(""+line.charAt(4));

      reset();

      for (int row = 0; row<7; row++) { 
	  checkLine(line, row);
	  line = reader.readLine();
      }

      line = reader.readLine(); // second empty line

      int hours = -1;

      for (int h = 0; h<24; h++) { 
	 if ((posshh.contains(h/10))&&(posshl.contains(h%10))) {
	    if (hours==-1) {
		hours=h;
	    } else {
		System.out.println("ambiguous");
		continue outer;
	    }
	 }
      }
      
      int mins = -1;

      for (int m = 0; m<60; m++) { 
	 if ((possmh.contains(m/10))&&(possml.contains(m%10))) {
	    if (mins==-1) {
		mins=m;
	    } else {
		System.out.println("ambiguous");
		continue outer;
	    }
	 }
      }

      if (hours<10) {
	System.out.print("0");
      }
	
      System.out.print(hours+":");

      if (mins<10) {
	System.out.print("0");
      }

      System.out.print(mins);

      System.out.println();

//      System.out.println(Arrays.toString(params));

    }


  }

  public static int toInt(String text) {
    return Integer.parseInt(text);
  }

  static Set<Integer> posshh= new HashSet<Integer>(), 
		  posshl= new HashSet<Integer>(), 
		  possmh= new HashSet<Integer>(), 
		  possml= new HashSet<Integer>();

  static final Set<Integer> ALL10 = new HashSet<Integer>();
  static {
	for (int n : new Integer[ ]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) {
	    ALL10.add(n);
	}
  }
  
  static void reset() {
	posshh.addAll(ALL10);
	posshl.addAll(ALL10);
	possmh.addAll(ALL10);
	possml.addAll(ALL10);    
  }

// hours minutes higher / lower
    static void checkLine(String line, int row) {
	check(posshh, line.substring(0, 5), row);
	check(posshl, line.substring(7, 7+5), row);
	check(possmh, line.substring(17, 17+5), row);
	check(possml, line.substring(24, 24+5), row);
//	return rows[hh][row] + "  "+rows[hl][row]+"  "+(((row==2)||(row==4))?"o":" ")+"  "+rows[mh][row]+"  "+rows[ml][row];
    }

    static void check(Set<Integer> poss, String scan, int row)  {

	  for (Iterator<Integer> it = poss.iterator() ; it.hasNext() ;) {
	    int num = (it.next());
	    if (!possible(scan, rows[num][row])) {
	        it.remove();
	    }
	  }

//	for (int num:poss) {
//	    if (!possible(scan, rows[num][row])) {
//	        poss.remove(num);/
//	    }
//	} 
    }

    static final String HL_101 = "+   +"; 
    static final String HL_111 = "+---+";
    static final String HL_001 = "    +";
    
    static final String VL_11 = "|   |";
    static final String VL_10 = "|    ";
    static final String VL_01 = "    |";
    static final String VL_00 = "     ";

    // number, row
     static final String [][] rows = new String [][] {
	{HL_111 , VL_11, VL_11, HL_101, VL_11, VL_11, HL_111}, // 0
	{HL_001 , VL_01, VL_01, HL_001, VL_01, VL_01, HL_001}, // 1
	{HL_111 , VL_01, VL_01, HL_111, VL_10, VL_10, HL_111}, // 2
	{HL_111 , VL_01, VL_01, HL_111, VL_01, VL_01, HL_111}, // 3
	{HL_101 , VL_11, VL_11, HL_111, VL_01, VL_01, HL_001}, // 4
	{HL_111 , VL_10, VL_10, HL_111, VL_01, VL_01, HL_111}, // 5
	{HL_111 , VL_10, VL_10, HL_111, VL_11, VL_11, HL_111}, // 6
	{HL_111 , VL_01, VL_01, HL_001, VL_01, VL_01, HL_001}, // 7
	{HL_111 , VL_11, VL_11, HL_111, VL_11, VL_11, HL_111}, // 8
	{HL_111 , VL_11, VL_11, HL_111, VL_01, VL_01, HL_111} // 9
    };

    static boolean possible(String scan, String val) {
	for (int i = 0; i<5; i++) {
	  if (scan.charAt(i)!='.') {
	     if (scan.charAt(i)!=val.charAt(i)) { return false;}
	  } 
	}
	return true;
    }

}