as = [] gets.to_i.times do as << gets.split.map(&:to_i) end as.sort! { |(a1,b1),(a2,b2)| a2.to_f/b2<=>a1.to_f/b1 } as.each do |a| puts "#{a[0]} #{a[1]}" end