from fractions import Fraction N, *AB = map(int, open(0).read().split()) for _, a, b in reversed(sorted((Fraction(a, b), a, b) for a, b in zip(*[iter(AB)] * 2))): print(a, b)