n = gets.to_i r = [] n.times do a, b = gets.split.map(&:to_i) r << [Rational(a, b), a, b] end r.sort.reverse_each do |_, a, b| puts "#{a} #{b}" end