import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from fractions import Fraction N = int(readline()) m = map(int,read().split()) AB = zip(m,m) fracs = sorted((Fraction(x,y) for x,y in AB), reverse=True) for x in fracs: print(x.numerator, x.denominator)