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

public class cc {
	
		
	public static void main (String[] args) throws IOException {
		String[][] nums = new String[10][];
		String[][] rums = new String[4][8];

	String[] x = new String[] {
		"+---+",
		"|   |",
		"|   |",
		"+   +",
		"|   |",
		"|   |",
		"+---+"};
	nums[0] = x;
	
	x = new String[] {
		"    +",
		"    |",
		"    |",
		"    +",
		"    |",
		"    |",
		"    +"};
		
		nums[1] = x;
	x = new String[] {
		"+---+",
		"    |",
		"    |",
		"+---+",
		"|    ",
		"|    ",
		"+---+"};
		nums[2] = x;
		
	x = new String[] {
		"+---+",
		"    |",
		"    |",
		"+---+",
		"    |",
		"    |",
		"+---+"};
		nums[3] = x;
		x = new String[] {
		"+   +",
		"|   |",
		"|   |",
		"+---+",
		"    |",
		"    |",
		"    +"};
		nums[4] = x;
	x = new String[] {
		"+---+",
		"|    ",
		"|    ",
		"+---+",
		"    |",
		"    |",
		"+---+"};
		nums[5] = x;
	x = new String[] {
		"+---+",
		"|    ",
		"|    ",
		"+---+",
		"|   |",
		"|   |",
		"+---+"};
		nums[6] = x;
	x = new String[] {
		"+---+",
		"    |",
		"    |",
		"    +",
		"    |",
		"    |",
		"    +"};
		nums[7] = x;
	x = new String[] {
		"+---+",
		"|   |",
		"|   |",
		"+---+",
		"|   |",
		"|   |",
		"+---+"};
		nums[8] = x;
	x = new String[] {
		"+---+",
		"|   |",
		"|   |",
		"+---+",
		"    |",
		"    |",
		"+---+"};
	nums[9] = x;
	String[] nc = {
		"     ",
		"     ",
		"  o  ",
		"     ",
		"  o  ",
		"     ",
		"     "};
	
	
		
		
		//System.out.println("");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String line;
		boolean check = false;
		int pos = 0;
		while ((line = br.readLine()) != null) {
			if (line.equals("end")) {
				break;
			}
			
			if (line.equals(""))  {
				if(check){
					System.out.println(check(nums, rums));
				}
				rums = new String[4][8];
				pos = 0;
				check = false;
				continue;
			}
			
			rums[0][pos] = line.substring(0,5);
			rums[1][pos] = line.substring(7,7+5);
			rums[2][pos] = line.substring(17,17+5);
			rums[3][pos] = line.substring(24,24+5);
			 check = true;
			pos++;
		}
		System.out.println("end");

	}
	
	
	public static String check(String[][] nums, String[][] rums) {
		boolean ok[][] = new boolean[4][10];
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 10; j++) {
				ok[i][j] = true;
			}
		}
		
		for (int i = 0; i < 4; i++) {
			for (int r = 0; r < 7; r++) {
				for (int c = 0; c < 5; c++) {
					//System.out.println(i +":"+r +":"+c + ".." + rums[i][r]);
					//System.out.flush();
					if (rums[i][r].charAt(c) == '.') {
						continue;
					}
					for (int n = 0; n < 10; n++) {
						if (rums[i][r].charAt(c) != nums[n][r].charAt(c)) {
							ok[i][n] = false;
						}
					}
				}
			}
		}
	
		
		/*System.out.println(Arrays.toString(ok[0]));
		System.out.println(Arrays.toString(ok[1]));
		System.out.println(Arrays.toString(ok[2]));
		System.out.println(Arrays.toString(ok[3]));*/
		
		//int x1, x2, x3, x4;
		for(int i=0; i<4; i++){
			boolean go = false;
			for(int n=0;n<10;n++){
				go = go || ok[i][n];
			}
			if(go == false){
				return "ambiguous";
			}
			
		}
	
		ArrayList<Integer> x0 = new ArrayList<Integer>(),
							x1 = new ArrayList<Integer>(),
							x2 = new ArrayList<Integer>(),
							x3 = new ArrayList<Integer>();
	
		for(int n=0;n<3;n++){
			if(ok[0][n]){
				x0.add(n);
			}
		}
		for(int n=0;n<10;n++){
			if(ok[1][n]){
				x1.add(n);
			}
		}
		for(int n=0;n<6;n++){
			if(ok[2][n]){
				x2.add(n);
			}
		}
		for(int n=0;n<10;n++){
			if(ok[3][n]){
				x3.add(n);
			}
		}
			
		/*for(int i = 0; i< x2.size(); i++){
			if(x2.get(i) > 5){
				x2.remove(i);
			}
		}
		
		for(int i = 0; i< x0.size(); i++){
			if(x0.get(i) > 2){
				x0.remove(i);
			}
		}*/
		
		Collections.sort(x0);
		Collections.sort(x1);
		Collections.sort(x2);
		Collections.sort(x3);
		
		if(x1.get(0) > 3){
			x0.remove(new Integer(2));
		}
		
/*		System.out.println(x0);
		System.out.println(x1);
		System.out.println(x2);
		System.out.println(x3);*/
		
		if(x0.size() != 1 || x1.size() != 1 || x2.size() != 1 || x3.size() != 1){
			return "ambiguous";
		}
		return Integer.toString(x0.get(0))+""+Integer.toString(x1.get(0))+":"+Integer.toString(x2.get(0))+""+Integer.toString(x3.get(0));
		
	}
}
 
