n = int(input()) AB = [] X = [] for i in range(n): a, b = map(int, input().split()) X.append(b) AB.append((a, b)) #import fractions import math from functools import reduce def lcm_base(x, y): #return (x * y) // fractions.gcd(x, y) return (x * y) // math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) l = lcm_list(X) ans = [] for a, b in AB: c = a*(l//b) ans.append((c, a, b)) ans.sort(reverse=True) for c, a, b in ans: print(a, b)