while True:
    try:
        d = {
            "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,
        }
        s1, s2 = input().split("-")  # 注意s1和s2是字符串格式
        c1 = s1.split()
        c2 = s2.split()
        # print(s1,s2,c1,c2)
        def isboom(lst):
            if len(lst) == 4 and len(set(lst)) == 1:
                return True
            return False

        if len(c1) == len(c2):  # 同种牌,比较第一张牌的大小
            if d[c1[0]] > d[c2[0]]:
                print(s1)
            else:
                print(s2)

        else:  # 不同种牌
            if ("joker JOKER" in s1) or ("joker JOKER" in s2):
                print("joker JOKER")
            elif isboom(c1):
                print(s1)
            elif isboom(c2):
                print(s2)
            else:
                print("ERROR")

    except:
        break