HW = [[c] + [int(x) for x in input().split()] for c in "ABC"] HW.sort(reverse=True, key=lambda x: (x[1], -x[2])) for x in HW: print(x[0])