
import java.util.ArrayList;
import java.io.FileReader;
import java.io.BufferedReader;
import java.math.BigInteger;
import java.util.Scanner;

class f
{
	ArrayList<Boolean> A;
	ArrayList<Boolean> B;
	Quad QA;
	Quad QB;
	String SA;
	String SB;
	BigInteger IA;
	BigInteger IB;
	BigInteger Zero;
	BigInteger One;
    

	static public void main(String Args[]) throws Exception
	{
		f zop=new f();
	}
    
    public f() throws Exception
    {
        
        Zero=new BigInteger("0");
        One=new BigInteger("1");
        
			Scanner IN=new Scanner(System.in);
        
        SA=IN.next();
        SB=IN.next();
        
        while ( (SA.compareTo(new String("0")) != 0) || (SB.compareTo(new String("0")) != 0))
        {
            
            IA=new BigInteger(SA,16);
            IB=new BigInteger(SB,16);
            
            
            //decompose
            A=decomp(IA);
            B=decomp(IB);
            
            
            QA=new Quad(A);
            QB=new Quad(B);
            //QA.Q.Comp();
            //QB.Q.Comp();
            
            
            
            Quad QResult=new Quad(QA,QB);
            QResult.Q.Comp();
            

            
            String ResStr=QResult.Print();
            ResStr="1"+ResStr;
            System.out.print(SA + " & " + SB + " = ");
            
            BigInteger BI=new BigInteger(ResStr,2);
            System.out.print(BI.toString(16).toUpperCase());
            System.out.println(" (" + ResStr + ")");
            

        
        
            SA=IN.next();
            SB=IN.next();        
        }
        
        
        
    
    }
    
  
    public ArrayList<Boolean> decomp(BigInteger BI)
    {
        ArrayList<Boolean> AL=new ArrayList<Boolean>();

        
        for (int i=BI.bitLength()-2; i>=0; i--)
        {
            AL.add(new Boolean(BI.testBit(i)));
            
        
        }
        return AL;
    
    
    }
    

    
    class Quad
    {
    
        class QuadSeg
        {
            public QuadSeg Q[];
            public boolean Frag;
            public boolean Color;
            
           
            public QuadSeg()
            {
                Q=new QuadSeg[4];
                Frag=false;
                Color=false;
                
            
            }
            
            
            public QuadSeg And(QuadSeg Oth)
            {
                if ((!Frag) && (!Color)) return this;
                if ((!Oth.Frag) && (!Oth.Color)) return Oth;
                if ((!Frag) && (Color)) return Oth;
                if ((!Oth.Frag) && (Oth.Color)) return this;
                
                
                QuadSeg newQ=new QuadSeg();
                newQ.Frag=true;
                newQ.Q[0]=Q[0].And(Oth.Q[0]);
                newQ.Q[1]=Q[1].And(Oth.Q[1]);
                newQ.Q[2]=Q[2].And(Oth.Q[2]);
                newQ.Q[3]=Q[3].And(Oth.Q[3]);
                
                
                return newQ;
            
            
            }
            
            public void Comp()
            {
                if (Frag)
                {
                    Q[0].Comp();
                    Q[1].Comp();
                    Q[2].Comp();
                    Q[3].Comp();
                    
                    Color=Q[0].Color;
                    boolean Ok=true;
                    for (int i=0; i<4; i++)
                    {
                        if ((Q[i].Color != Color) || (Q[i].Frag))
                        {
                            Ok=false;
                        }
                    }
                    if (Ok)
                    {
                        Frag=false;
                    }
                
                }
                
            
            }
            
            public String Print()
            {
                String Str="";
                if (Frag)
                {
                    Str="0";
                    Str+=Q[0].Print();
                    Str+=Q[1].Print();
                    Str+=Q[2].Print();
                    Str+=Q[3].Print();
                    
                
                }
                else
                {
                    Str="1";
                    if (Color) Str+="1";
                    else Str+="0";
                
                }
                return Str;
            
            }
        
        }
        
        int MaxDepth;
        public QuadSeg Q;
        private int index;
        
        public Quad(ArrayList<Boolean> AL)
        {
        

            
            MaxDepth=0;
            index=0;
            Q=decomp(AL,0);
            
   
        
        
        }
        
        public Quad(Quad QA, Quad QB)
        {
            MaxDepth=0;
            Q=QA.Q.And(QB.Q);
        
        
        }
        
        public QuadSeg decomp(ArrayList<Boolean> AL, int Depth)
        {
            if (Depth >= MaxDepth) MaxDepth=Depth;
            
            QuadSeg QS=new QuadSeg();
            
            boolean b=(AL.get(index)).booleanValue();
            index++;
            if (b)
            {
                
                QS.Frag=false;
                QS.Color=(AL.get(index)).booleanValue();
                index++;
            
            }
            else
            {
                QS.Frag=true;
                QS.Q[0]=decomp(AL,Depth+1);
                QS.Q[1]=decomp(AL,Depth+1);
                QS.Q[2]=decomp(AL,Depth+1);
                QS.Q[3]=decomp(AL,Depth+1);
            
            }
                
            
            return QS;
        
        }
        

        
        String Print()
        {
            String str="";
            str=Q.Print();
            
            return str;
        
        
        }
	}
}
