//Arrum Shin
//Bergen County Academies
//Intermediate
#include 
using namespace std;
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define fornn(i,n) for(int i=1; i<(int)n; i++)
#define fornb(i,n) for(int i=n-1; i>-1; i--)
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef vector vi;
int main () {
    freopen("3int_sampledata.txt","r",stdin);
    for(int z=0; z<5; z++) {
        vector> v(4,vector(4));
        string s;
        cin>>s;
        string ans="";
        int i=0;
        bool n=0;
        while(i a(4); //0 didn't appear, 1 true, -1 false
            while(s[i]!='+' && i-1 && s[i]-'A'<5) {
                    if(n)
                        a[s[i]-'A']=-1;
                    else
                        a[s[i]-'A']=1;
                }
                n=0;
                if(s[i]=='~')
                    n=1;
                i++;
            }
            vector> b(4,vector(4)); //which rows/columns work
            forn(x,4) {
                if(a[x]==0) {
                    b[x][0]=1; b[x][1]=1; b[x][2]=1; b[x][3]=1;
                }
                else if(a[x]==1) {
                    if(x==0||x==1) {
                        b[x][0]=1; b[x][1]=1;
                    }
                    else {
                        b[x][1]=1; b[x][2]=1;
                    }
                }
                else if(a[x]==-1) {
                    if(x==0||x==1) {
                        b[x][2]=1; b[x][3]=1;
                    }
                    else {
                        b[x][0]=1; b[x][3]=1;
                    }
                }
            }
            forn(j,4) {
                forn(k,4) {
                    if(b[1][j]&&b[3][j]&&b[0][k]&&b[2][k])
                        v[j][k]=1;
                }
            }
            i++;
        }
        forn(i,4) {
            int y=0;
            forn(j,4) {
                if(v[i][j]==1)
                    y+=pow(2,3-j);
            }
            if(y>=10)
                ans+=(char)(y+55);
            else
                ans+=y+'0';
        }
        cout<