//Gregory Pylypovych
//Bergen County Academies
//Senior


#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

int main(){
	vector> v(4, vector(4));
	ifstream fin("3sr_sampledata.txt");
	//ofstream fout("coolinput.txt");
	string s;
	int temp;
	int count;
	int q;
	vector autumn;
	string result_string="";
	vector carolanneduffy;
	vector bobs;


	for(int qrs=0; qrs<5; qrs++){
	fin>>s;

	//COnvert the four hexadecimal characters into a  four by four matrix of x's
	for(int i=0; i<4; i++){
		temp=(int) s[i];
		if(temp<63){
			temp=temp-48;
		}
		else{
			temp=temp-55;
		}
		count=3;
		while(count!=-1){
			q=temp%2;
			temp=temp/2;
			v[i][count]=q;
			count--;
		}
	}
	result_string="";

	//Checking for 8 box regions and removing 1's in those boxes
	if(v[0][0]*v[0][1]*v[0][2]*v[0][3]*v[1][0]*v[1][1]*v[1][2]*v[1][3]==1){ result_string=result_string+"B+"; for(int i=0; i<4; i++){ v[0][i]=0; v[1][i]=0;}}
	if(v[1][0]*v[1][1]*v[1][2]*v[1][3]*v[2][0]*v[2][1]*v[2][2]*v[2][3]==1){ result_string=result_string+"D+"; for(int i=0; i<4; i++){ v[1][i]=0; v[2][i]=0;}}
	if(v[2][0]*v[2][1]*v[2][2]*v[2][3]*v[3][0]*v[3][1]*v[3][2]*v[3][3]==1){ result_string=result_string+"~B+"; for(int i=0; i<4; i++){ v[2][i]=0; v[3][i]=0;}}
	
	if(v[0][0]*v[1][0]*v[2][0]*v[3][0]*v[0][1]*v[1][1]*v[2][1]*v[3][1]==1){ result_string=result_string+"A+"; for(int i=0; i<4; i++){ v[i][0]=0; v[i][1]=0;}}
	if(v[0][1]*v[1][1]*v[2][1]*v[3][1]*v[0][2]*v[1][2]*v[2][2]*v[3][2]==1){ result_string=result_string+"C+"; for(int i=0; i<4; i++){ v[i][1]=0; v[i][2]=0;}}
	if(v[0][2]*v[1][2]*v[2][2]*v[3][2]*v[0][3]*v[1][3]*v[2][3]*v[3][3]==1){ result_string=result_string+"~A+"; for(int i=0; i<4; i++){ v[i][2]=0; v[i][3]=0;}}

	if(v[0][0]*v[1][0]*v[2][0]*v[3][0]*v[0][3]*v[1][3]*v[2][3]*v[3][3]==1){ result_string=result_string+"~C+"; for(int i=0; i<4; i++){ v[i][0]=0; v[i][3]=0;}}
	if(v[0][0]*v[0][1]*v[0][2]*v[0][3]*v[3][0]*v[3][1]*v[3][2]*v[3][3]==1){ result_string=result_string+"~D+"; for(int i=0; i<4; i++){ v[0][i]=0; v[3][i]=0;}}

	//Checking for 4 adjacent boxes
	if(v[0][0]*v[0][1]*v[0][2]*v[0][3]==1){ result_string=result_string+"B~D+"; for(int i=0; i<4; i++){ v[0][i]=0;}}
	if(v[1][0]*v[1][1]*v[1][2]*v[1][3]==1){ result_string=result_string+"BD+"; for(int i=0; i<4; i++){ v[1][i]=0;}}
	if(v[2][0]*v[2][1]*v[2][2]*v[2][3]==1){ result_string=result_string+"~BD+"; for(int i=0; i<4; i++){ v[2][i]=0;}}
	if(v[3][0]*v[3][1]*v[3][2]*v[3][3]==1){ result_string=result_string+"~B~D+"; for(int i=0; i<4; i++){ v[3][i]=0;}}
	
	if(v[0][0]*v[1][0]*v[2][0]*v[3][0]==1){ result_string=result_string+"A~C+"; for(int i=0; i<4; i++){ v[i][0]=0;}}
	if(v[0][1]*v[1][1]*v[2][1]*v[3][1]==1){ result_string=result_string+"AC+"; for(int i=0; i<4; i++){ v[i][1]=0;}}
	if(v[0][2]*v[1][2]*v[2][2]*v[3][2]==1){ result_string=result_string+"~AC+"; for(int i=0; i<4; i++){ v[i][2]=0;}}
	if(v[0][3]*v[1][3]*v[2][3]*v[3][3]==1){ result_string=result_string+"~A~C+"; for(int i=0; i<4; i++){ v[i][3]=0;}}

	autumn={"AB", "BC", "~AB", "AD", "CD", "~AD", "A~B", "~BC", "~A~B"};
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			if(v[i][j]*v[i][j+1]*v[i+1][j]*v[i+1][j+1]==1){ result_string=result_string+autumn[3*i+j]+"+"; v[i][j]=0; v[i][j+1]=0; v[i+1][j]=0; v[i+1][j+1]=0;}
		}
	}

	//Check for edge column and row thingies step 3

	if(v[0][0]*v[1][0]*v[0][3]*v[1][3]==1){ result_string=result_string+"B~C+"; v[0][0]=0; v[1][0]=0; v[0][3]=0; v[1][3]=0;}
	if(v[1][0]*v[2][0]*v[1][3]*v[2][3]==1){ result_string=result_string+"~CD+"; v[1][0]=0; v[2][0]=0; v[1][3]=0; v[2][3]=0;}
	if(v[2][0]*v[3][0]*v[2][3]*v[3][3]==1){ result_string=result_string+"~B~C+"; v[2][0]=0; v[3][0]=0; v[2][3]=0; v[3][3]=0;}

	if(v[0][0]*v[0][1]*v[3][0]*v[3][1]==1){ result_string=result_string+"A~D+"; v[0][0]=0; v[0][1]=0; v[3][0]=0; v[3][1]=0;}
	if(v[0][1]*v[0][2]*v[3][1]*v[3][2]==1){ result_string=result_string+"C~D+"; v[0][1]=0; v[0][2]=0; v[3][1]=0; v[3][2]=0;}
	if(v[0][2]*v[0][3]*v[3][2]*v[3][3]==1){ result_string=result_string+"~A~D+"; v[0][2]=0; v[0][3]=0; v[3][2]=0; v[3][3]=0;}

	//Check for four corners step 4
	if(v[0][0]*v[3][0]*v[0][3]*v[3][3]==1){ result_string=result_string+"~C~D+"; v[0][0]=0; v[3][0]=0; v[0][3]=0; v[3][3]=0;}

	//Check for step 5

	carolanneduffy={"AB~D", "BC~D", "~AB~D", "ABD", "BCD", "~ABD", "A~BD", "~BCD", "~A~BD", "A~B~D", "~BC~D", "~A~B~D"};
	for(int i=0; i<4; i++){
		for(int j=0; j<3; j++){
			if(v[i][j]*v[i][j+1]==1){ result_string=result_string+carolanneduffy[3*i+j]+"+"; v[i][j]=0; v[i][j+1]=0;}
		}
	}
	carolanneduffy={"AB~C", "ABC", "~ABC", "~AB~C", "A~CD", "ACD", "~ACD", "~A~CD", "A~B~C", "A~BC", "~A~BC", "~A~B~C"};
	for(int i=0; i<3; i++){
		for(int j=0; j<4; j++){
			if(v[i][j]*v[i+1][j]==1){ result_string=result_string+carolanneduffy[4*i+j]+"+"; v[i][j]=0; v[i+1][j]=0; }
		}
	}
	
	//Check for step 6
	if(v[0][0]*v[0][3]==1){ result_string=result_string+"B~C~D"+"+"; v[0][0]=0; v[0][3]=0;}
	if(v[1][0]*v[1][3]==1){ result_string=result_string+"B~CD"+"+"; v[1][0]=0; v[1][3]=0;}
	if(v[2][0]*v[2][3]==1){ result_string=result_string+"~B~CD"+"+"; v[2][0]=0; v[2][3]=0;}
	if(v[3][0]*v[3][3]==1){ result_string=result_string+"~B~C~D"+"+"; v[3][0]=0; v[3][3]=0;}

	if(v[0][0]*v[3][0]==1){ result_string=result_string+"A~C~D"+"+"; v[0][0]=0; v[3][0]=0;}
	if(v[0][1]*v[3][1]==1){ result_string=result_string+"AC~D"+"+"; v[0][1]=0; v[3][1]=0;}
	if(v[0][2]*v[3][2]==1){ result_string=result_string+"~AC~D"+"+"; v[0][2]=0; v[3][2]=0;}
	if(v[0][3]*v[3][3]==1){ result_string=result_string+"~A~C~D"+"+"; v[0][3]=0; v[3][3]=0;}
	
	//check for step 7
	bobs={"AB~C~D", "ABC~D", "~ABC~D", "~AB~C~D", "AB~CD", "ABCD", "~ABCD", "~AB~CD",
	 "A~B~CD", "A~BCD", "~A~BCD", "~A~B~CD", "A~B~C~D", "A~BC~D", "~A~BC~D", "~A~B~C~D"};
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			if(v[i][j]==1){ result_string=result_string+bobs[4*i+j]+"+"; v[i][j]=0;}
		}
	}
	//Displays output string
	result_string.erase(result_string.size()-1);
	cout<