num=5*7*8*9 n=int(input()) m=[list(map(int,input().split())) for _ in range(n)] ans=[] for i in range(n): ans.append([m[i][0]*num//m[i][1],i]) ans.sort(key=lambda x: x[0],reverse=True) for i in range(n): print(*m[ans[i][1]])