#include<iostream>

using namespace std;


typedef string tDig[7];

tDig T[10];

void init()
{
T[0][0] = "+---+";
T[0][1] = "|   |";
T[0][2] = "|   |"; 
T[0][3] = "+   +"; 
T[0][4] = "|   |"; 
T[0][5] = "|   |"; 
T[0][6] = "+---+"; 

T[1][0] = "    +";
T[1][1] = "    |";
T[1][2] = "    |"; 
T[1][3] = "    +"; 
T[1][4] = "    |"; 
T[1][5] = "    |"; 
T[1][6] = "    +"; 

T[2][0] = "+---+";
T[2][1] = "    |";
T[2][2] = "    |"; 
T[2][3] = "+---+"; 
T[2][4] = "|    "; 
T[2][5] = "|    "; 
T[2][6] = "+---+";

T[3][0] = "+---+";
T[3][1] = "    |";
T[3][2] = "    |"; 
T[3][3] = "+---+"; 
T[3][4] = "    |"; 
T[3][5] = "    |"; 
T[3][6] = "+---+"; 

T[4][0] = "+   +";
T[4][1] = "|   |";
T[4][2] = "|   |"; 
T[4][3] = "+---+"; 
T[4][4] = "    |"; 
T[4][5] = "    |"; 
T[4][6] = "    +";

T[5][0] = "+---+";
T[5][1] = "|    ";
T[5][2] = "|    "; 
T[5][3] = "+---+"; 
T[5][4] = "    |"; 
T[5][5] = "    |"; 
T[5][6] = "+---+"; 

T[6][0] = "+---+";
T[6][1] = "|    ";
T[6][2] = "|    "; 
T[6][3] = "+---+"; 
T[6][4] = "|   |"; 
T[6][5] = "|   |"; 
T[6][6] = "+---+"; 

T[7][0] = "+---+";
T[7][1] = "    |";
T[7][2] = "    |"; 
T[7][3] = "    +"; 
T[7][4] = "    |"; 
T[7][5] = "    |"; 
T[7][6] = "    +";

T[8][0] = "+---+";
T[8][1] = "|   |";
T[8][2] = "|   |"; 
T[8][3] = "+---+"; 
T[8][4] = "|   |"; 
T[8][5] = "|   |"; 
T[8][6] = "+---+"; 

T[9][0] = "+---+";
T[9][1] = "|   |";
T[9][2] = "|   |"; 
T[9][3] = "+---+"; 
T[9][4] = "    |"; 
T[9][5] = "    |"; 
T[9][6] = "+---+";
}


string M[4][7];
bool Moznosti[4][10];


bool Mozem(tDig A, tDig B)
{

	for(int i=0; i<=6; i++)for(int j=0; j<=4;j++) if (A[i][j] != '.' && B[i][j] != A[i][j])  return 0;
	return 1;
}



int main()
{
	init();
	string line;
	getline(cin, line);
	while(line!="end")
	{
		for(int i=0;i<=6;i++)
		{
			M[0][i] = line.substr(0,5);
			M[1][i] = line.substr(7,5);
			M[2][i] = line.substr(17,5);
			M[3][i] = line.substr(24,5);
			getline(cin, line);
		}
		
		for(int i=0;i<=3;i++)
			for(int j=0; j<=9; j++) Moznosti[i][j]= Mozem(M[i], T[j]);
		for(int i=3; i<=9; i++)Moznosti[0][i]=0;
		for(int i=6; i<=9; i++)Moznosti[2][i]=0;

		int pocet=0;;
		for(int i=0; i<=9; i++) pocet+=Moznosti[1][i];
		if (pocet == 1) for(int i=0; i<=9; i++) if (Moznosti[1][i] && i>=4) Moznosti[0][2] = 0;
/*
		for(int i=0;i<=3;i++)
		{	cout << "DO " << i <<" : ";
			for(int j=0; j<=9; j++) if (Moznosti[i][j]) cout << j << " ";
			cout << endl;
		}
*/
		int a=0, b=0, c=0, d=0;
		for(int j=0; j<=9; j++)a+=Moznosti[0][j];
		for(int j=0; j<=9; j++)b+=Moznosti[1][j];
		for(int j=0; j<=9; j++)c+=Moznosti[2][j];
		for(int j=0; j<=9; j++)d+=Moznosti[3][j];

		if (a==1 && b==1 && c==1 && d==1)
		{
			for(int j=0; j<=9; j++) if (Moznosti[0][j]) cout << j;
			for(int j=0; j<=9; j++) if (Moznosti[1][j]) cout << j;
			cout <<":";
			for(int j=0; j<=9; j++) if (Moznosti[2][j]) cout << j;
			for(int j=0; j<=9; j++) if (Moznosti[3][j]) cout << j;
			cout<<endl;
		}else cout << "ambiguous" << endl;
		cin.get();
		getline(cin, line);
	}
	cout << "end" << endl;

	return 0;
}



