import java.util.*;

public class cc {

	Scanner sc = new Scanner(System.in);

	char[][] array = new char[7][29];
	
	void solve(){
	
		String s;
	
		while (fillArray()){			
			List<Integer> first = findDigits(0);
			List<Integer> second = findDigits(7);
			List<Integer> third = findDigits(17);
			List<Integer> fourth = findDigits(24);
			
			for(int i=9; i>2; i--){
				first.remove(new Integer(i));
			}
			for(int i=9; i>6; i--){
				third.remove(new Integer(i));
			}
			
			int tmp;
			List<Integer> hodiny = new ArrayList<Integer>();
			for ( Integer prvaHodina : first) {
				for (Integer druhaHodina : second) {
					tmp = 10* prvaHodina + druhaHodina;
					if (tmp <= 23) {
						hodiny.add(tmp);
					}
				}
			}
			
			List<Integer> minuty = new ArrayList<Integer>();
			for ( Integer prvaMinuty : third) {
				for (Integer druhaMinuty : fourth) {
					tmp = 10* prvaMinuty + druhaMinuty;
					if (tmp <= 59) {
						minuty.add(tmp);
					}
				}
			}
			
			if (hodiny.size() == 1 && minuty.size() == 1) {
				printHours(hodiny.get(0),minuty.get(0)); 
			} else {
				print ("ambiguous");
			}
		}
		
		print("end");
	}
	
	void printHours(Integer hours, Integer minutes){
		if(hours < 10) System.out.print("0"+hours+":");
		else System.out.print(hours+":");
		if(minutes < 10) print("0"+minutes);
		else print(minutes+"");
	}
	
	List<Integer> findDigits(int index){
		List<Integer> list = new ArrayList<Integer>();
		if(checkZero(index)) list.add(0);
		if(checkOne(index)) list.add(1);
		if(checkTwo(index)) list.add(2);
		if(checkThree(index)) list.add(3);
		if(checkFour(index)) list.add(4);
		if(checkFive(index)) list.add(5);
		if(checkSix(index)) list.add(6);
		if(checkSeven(index)) list.add(7);
		if(checkEight(index)) list.add(8);
		if(checkNine(index)) list.add(9);
		return list;
	}
	
	boolean checkIfEdgeExistLittleCol(int row, int col){
		if(array[++row][col] == '|') return true;
		if(array[++row][col] == '|') return true;
		return false;
	}
	
	boolean checkIfEdgeExistLittleRow(int row, int col){
		if(array[row][++col] == '-') return true;
		if(array[row][++col] == '-') return true;
		if(array[row][++col] == '-') return true;
		return false;
	}
	
	boolean checkCornerExist(int x, int y){
		return (array[x][y] == '+');
	}

	boolean checkZero(int index){
		if(!checkCol(index)) return false;
		if(!checkCol(index + 4)) return false;
		if(!checkRow(0, index)) return false;
		if(!checkRow(6, index)) return false;
		
		if(checkIfEdgeExistLittleRow(3, index)) return false;
		
		return true;
	}
	
	boolean checkOne(int index){
		if(!checkCol(index + 4)) return false;
		
		if(checkIfEdgeExistLittleRow(0, index)) return false;
		if(checkIfEdgeExistLittleRow(3, index)) return false;
		if(checkIfEdgeExistLittleRow(6, index)) return false;
		
		if(checkIfEdgeExistLittleCol(0, index)) return false;
		if(checkIfEdgeExistLittleCol(3, index)) return false;
		
		if(checkCornerExist(0, index)) return false;
		if(checkCornerExist(3, index)) return false;
		if(checkCornerExist(6, index)) return false;
		
		return true;
	}
	
	boolean checkTwo(int index){
		if(!checkRow(0, index)) return false;
		if(!checkLittleCol(0, index + 4)) return false;
		if(!checkRow(3, index)) return false;
		if(!checkLittleCol(3, index)) return false;
		if(!checkRow(6, index)) return false;
		
		if(checkIfEdgeExistLittleCol(0, index)) return false;
		if(checkIfEdgeExistLittleCol(3, index + 4)) return false;
		
		return true;
	}
	
	boolean checkThree(int index){
		if(!checkRow(0, index)) return false;
		if(!checkLittleCol(0, index + 4)) return false;
		if(!checkRow(3, index)) return false;
		if(!checkLittleCol(3, index + 4)) return false;
		if(!checkRow(6, index)) return false;
		
		if(checkIfEdgeExistLittleCol(0, index)) return false;
		if(checkIfEdgeExistLittleCol(3, index)) return false;
		
		return true;
	}
	
	boolean checkFour(int index){
		if(!checkLittleCol(0, index)) return false;
		if(!checkRow(3, index)) return false;
		if(!checkCol(index + 4)) return false;
		
		if(checkIfEdgeExistLittleRow(0, index)) return false;
		if(checkIfEdgeExistLittleRow(6, index)) return false;		
		if(checkIfEdgeExistLittleCol(3, index)) return false;		
		if(checkCornerExist(6, index)) return false;
		
		return true;
	}
	
	boolean checkFive(int index){
		if(!checkRow(0, index)) return false;
		if(!checkLittleCol(0, index)) return false;
		if(!checkRow(3, index)) return false;
		if(!checkLittleCol(3, index + 4)) return false;
		if(!checkRow(6, index)) return false;
		
		if(checkIfEdgeExistLittleCol(0, index+4)) return false;
		if(checkIfEdgeExistLittleCol(3, index)) return false;
		
		return true;
	}
	
	boolean checkSix(int index){
		if(!checkRow(0, index)) return false;
		if(!checkLittleCol(0, index)) return false;
		if(!checkRow(3, index)) return false;
		if(!checkLittleCol(3, index)) return false;
		if(!checkLittleCol(3, index + 4)) return false;
		if(!checkRow(6, index)) return false;
		
		if(checkIfEdgeExistLittleCol(0, index+4)) return false;
		
		return true;
	}
	
	boolean checkSeven(int index){
		if(!checkRow(0, index)) return false;
		if(!checkCol(index + 4)) return false;
		
		if(checkIfEdgeExistLittleRow(3, index)) return false;
		if(checkIfEdgeExistLittleRow(6, index)) return false;
		
		if(checkIfEdgeExistLittleCol(0, index)) return false;
		if(checkIfEdgeExistLittleCol(3, index)) return false;
		
		if(checkCornerExist(3, index)) return false;
		if(checkCornerExist(6, index)) return false;
		
		return true;
	}
	
	boolean checkEight(int index){
		if(!checkCol(index)) return false;
		if(!checkCol(index + 4)) return false;
		if(!checkRow(0, index)) return false;
		if(!checkRow(3, index)) return false;
		if(!checkRow(6, index)) return false;
		
		return true;
	}
	
	boolean checkNine(int index){
		if(!checkRow(0, index)) return false;
		if(!checkLittleCol(0, index + 4)) return false;
		if(!checkRow(3, index)) return false;
		if(!checkLittleCol(3, index + 4)) return false;
		if(!checkRow(6, index)) return false;
		if(!checkLittleCol(0, index)) return false;
		
		if(checkIfEdgeExistLittleCol(3, index)) return false;
		
		return true;
	}
	
	boolean checkRow(int row, int col){
		if(array[row][col] != '+' && array[row][col] != '.') return false;
		col++;
		if(array[row][col] != '-' && array[row][col] != '.') return false;
		col++;
		if(array[row][col] != '-' && array[row][col] != '.') return false;
		col++;
		if(array[row][col] != '-' && array[row][col] != '.') return false;
		col++;
		if(array[row][col] != '+' && array[row][col] != '.') return false;
		
		return true;
	}
	
	boolean checkLittleCol(int row, int col){	
		if(array[row][col] != '+' && array[row][col] != '.') return false;
		row++;
		if(array[row][col] != '|' && array[row][col] != '.') return false;
		row++;
		if(array[row][col] != '|' && array[row][col] != '.') return false;
		row++;
		if(array[row][col] != '+' && array[row][col] != '.') return false;
		
		return true;
	}
	
	boolean checkCol(int colIndex){	
		if(array[0][colIndex] != '+' && array[0][colIndex] != '.') return false;
		if(array[1][colIndex] != '|' && array[1][colIndex] != '.') return false;
		if(array[2][colIndex] != '|' && array[2][colIndex] != '.') return false;
		if(array[3][colIndex] != '+' && array[3][colIndex] != '.') return false;
		if(array[4][colIndex] != '|' && array[4][colIndex] != '.') return false;
		if(array[5][colIndex] != '|' && array[5][colIndex] != '.') return false;
		if(array[6][colIndex] != '+' && array[6][colIndex] != '.') return false;
		
		return true;
	}
	
	
	boolean fillArray(){
		String s;
		s = sc.nextLine();
		if(s.equals("end")) return false;
		for( int i = 0; i < 7; i ++){
			if (i > 0) s = sc.nextLine();
			for( int j = 0; j < 29; j ++){
				array[i][j] = s.charAt(j);
			}
		}
		sc.nextLine();
		sc.nextLine();
		return true;
	}


	// template
	public static void main(String[] args){
		new cc().solve();		
	}
	
	void print(){
		System.out.println();
	}
	
	void print(String s){
		if (s == null){
			s = "";
		}
		System.out.println(s);
	}

}
