from fractions import Fraction n = int(input()) fracs = [] for _ in range(n): a, b = map(int, input().split()) fracs.append([Fraction(a, b), a, b]) fracs.sort(reverse=True) for t in fracs: print(t[1], t[2])