from fractions import Fraction def main(): N = int(input()) A = [] for i in range(N): a, b = map(int, input().split()) A.append((Fraction(a, b), a, b)) A.sort(reverse=True) for a, b, c in A: print(b, c) if __name__ == '__main__': main()