lst = [] abc = 'ABC' for c in abc: h, w = map(int, input().split()) lst.append((-h, w, c)) lst.sort() for h, w, c in lst: print(c)