while 1: try: s=input().split('-') s1=s[0].split() s2=s[1].split() # 用列表索引号表示牌面大小顺序 rank=['3','4','5','6','7','8','9','10','J','Q','K','A','2','joker','JOKER'] if len(s1)!=len(s2): if s1==['joker','JOKER'] or s2==['joker','JOKER']: print('joker JOKER') elif len(s1)==4 and s2!=['joker','JOKER']: print(' '.join(s1)) elif len(s2)==4 and s1!=['joker','JOKER']: print(' '.join(s2)) else: print('ERROR') elif len(s1)==len(s2): if rank.index(s1[0])>rank.index(s2[0]): print(' '.join(s1)) else: print(' '.join(s2)) except: break