const readline = require("readline")
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const brandIndex = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2', 'joker', 'JOKER']
rl.on('line', function(line){
const brands = line.trim().split('-')
let result = compare(brands[0].split(' '), brands[1].split(' '))
if(typeof result !== 'string'){
console.log(result.join(' '))
}else {
console.log(result)
}
})
// 获取当前手上牌的类型
function getTypeOfBrand(brand){
let type
if(brand.length === 1){
// 个子
type = 1
}else if(brand.length === 2){
// 对子或王炸
if(brand.indexOf('joker') > -1){
type = 99
}else{
type = 2
}
}else if(brand.length === 3){
// 三个
type = 3
}else if(brand.length === 4){
// 炸弹
type = 88
}else if(brand.length === 5){
// 顺子
type = 5
}
return type
}
function compare(brand1, brand2){
let type1 = getTypeOfBrand(brand1)
let type2 = getTypeOfBrand(brand2)
// 一方是王炸
if(type1 === 99 || type2 === 99){
return type1 === 99 ? brand1 : brand2
}
// 两个都是炸弹
if(type1 === 88 && type2 === 88){
return brandIndex.indexOf(brand1[0]) > brandIndex.indexOf(brand2[0]) ? brand1 : brand2
}
// 只有一个是炸弹
if(type1 === 88 || type2 === 88){
return type1 === 88 ? brand1 : brand2
}
// 接下来就没有炸弹,比较最小牌大小即可得出结果
// 如果不是同类型的牌,无法比较
if(type1 !== type2){
return 'ERROR'
}else{
// 比较最小,谁大输出谁
if(brandIndex.indexOf(brand1[0]) > brandIndex.indexOf(brand2[0])){
return brand1
}else {
return brand2
}
}
}