n = int(input()) mp = [] kei = 1 for i in range(n): a,b = map(int,input().split()) mp.append([0,a,b]) kei *= b for i in range(n): mp[i][0] = kei//mp[i][2]*mp[i][1] mp.sort(reverse=True) for i in range(n): print(mp[i][1],mp[i][2])