#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
string FindMaxCard(const string&line)
{
//先查找是否存在大小王
int pos=line.find("joker JOKER");
if(pos!=-1)
{
return "joker JOKER";
}
//分割两张牌统计牌张数
pos=line.find('-');
string card1=line.substr(0,pos);
string card2=line.substr(pos+1);
int cnt1=count(card1.begin(),card1.end(),' ')+1;
int cnt2=count(card2.begin(),card2.end(),' ')+1;
//拿到第一张牌
string first1=card1.substr(0,card1.find(' '));
string first2=card2.substr(0,card2.find(' '));
//同类型的牌比较第一张大小即可
if(cnt1==cnt2)
{ //将牌的大小进行简单的映射用来比较大小关系
string tem="3 4 5 6 7 8 9 10 J Q K A 2 j";
if(tem.find(first1)>tem.find(first2))
{
return card1;
}
else
{
return card2;
}
}
//如果张数不相等用来判断是否有炸弹
if(cnt1==4)
{
return card1;
}
else if(cnt2==4)
{
return card2;
}
return "ERROR";
}
int main() {
string line;
while(getline(cin,line))
{
string ret=FindMaxCard(line);
cout<<ret<<endl;
}
return 0;
}