n=int(input()) AB=[list(map(int,input().split())) for i in range(n)] PRO=1 for a,b in AB: PRO=PRO*b AB.sort(key=lambda x:x[0]*PRO//x[1],reverse=True) for a,b in AB: print(a,b)