N = gets.to_i r = N.times.map { gets.split.map(&:to_i) } r.sort_by! { |a, b| -Rational(a, b) } puts r.map { |a, b| [a, b].join(' ') }