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