def ascan; gets.split.map(&:to_i); end gets.to_i.times.map{Rational(*ascan)}.sort.reverse.each{|f| puts "#{f.numerator} #{f.denominator}"}