S = 'ABC' l = [list(map(int, input().split())) for i in range(3)] for i in range(3): l[i].apend(S[i]) l.sort(key=lambda x: (x[0], -x[1]), reverse=True) print(*list(map(lambda x: x[2], l)), sep=True)