N=range(int(input())) C=[] D=[] for i in N: C.append(input()) A,B=map(int,C[i].split()) D.append(A/B) E=sorted(D) E.reverse() for F in E: for i in N: if(F==D[i]):print(C[i])