from fractions import Fraction n = int(input()) AB = [list(map(int, input().split())) for _ in range(n)] for i in range(n): A, B = AB[i] AB[i].append(Fraction(A, B)) AB.sort(key = lambda x: x[2], reverse = True) for i in AB: print (i[0], i[1])