dic={} n = input() for i in range(n): content = input() dic[int(content[0]/content[1])] = content sorted_list = sorted(dic,reverse = True) for j in sorted_list: print(j)