def ascan; gets.split.map(&:to_i); end gets.to_i.times.map{a=ascan;[Rational(*a), a]}.sort.reverse.each{|f,a| puts a*" "}