// 3 4
// 33 44
// 333 444
// 34567 45678
// 3333 4444
// jJ
let order = '345678910JQKA2jokerJOKER'
let normal = ['个子', '三个', '对子', '顺子']
let sep = ['对王', '炸弹']
function getType(arr) {
    if(arr.length==1)return '个子'
    if(arr[0]=='joker')return '对王'
    if(arr.length==2)return '对子'
    if(arr.length==3)return '三个'
    if(arr.length==4)return '炸弹'
    if(arr.length==5)return '顺子'
}
let s = readline().split('-')
let a = s[0].split(' ')
let b = s[1].split(' ')
print(compare(a, b))
function compare(a, b) {
    let at = getType(a)
    let bt = getType(b)
    let att = sep.includes(at)? 'sep':'normal'
    let btt = sep.includes(bt)? 'sep':'normal'
    if(normal.includes(at) && normal.includes(bt) && at!==bt)return 'ERROR'
    if([at, bt].includes('对王'))return 'joker JOKER'
    if(att!==btt)return att=='sep'?a.join(' '):b.join(' ')
    return order.indexOf(a[0])>order.indexOf(b[0])?a.join(' '):b.join(' ')
}