#include<bits/stdc++.h>
using namespace std;
map<string,int> m={{"3",3},{"4",4},{"5",5},{"6",6},{"7",7},{"8",8},{"9",9},{"10",10},
                   {"J",11},{"Q",12},{"k",13},{"A",14},{"2",15},{"joker",16},{"JOKER",17}};
int main()
{
    string str;
    while(getline(cin,str))
    {
        istringstream ss,ss1,ss2;
        vector<string> v,one,two;
        ss.str(str);
        for(string t;getline(ss,t,'-');v.push_back(t));
        ss1.str(v[0]);
        for(string t;getline(ss1,t,' ');one.push_back(t));
        ss2.str(v[1]);
        for(string t;getline(ss2,t,' ');two.push_back(t));
        if(one.size()==two.size())
            if(m[one[0]]>m[two[0]])cout<<v[0]<<endl;
            else cout<<v[1]<<endl;
        else
            if(one.size()==2&&m[one[0]]+m[one[1]]==33) cout<<v[0]<<endl;
            else if(two.size()==2&&m[two[0]]+m[two[1]]==33) cout<<v[1]<<endl;
            else if(one.size()==4) cout<<v[0]<<endl;
            else if(two.size()==4) cout<<v[1]<<endl;
            else cout<<"ERROR"<<endl;
    }
}