import Data.Ratio import Data.List import Control.Monad main = do n <- read <$> getLine mapM_ (\(x:y:[]) -> putStrLn (show x ++ " " ++ show y)) . sortBy (\x y -> let f (x:y:[]) = x % y in compare (f y) (f x)) . map (map read . words) =<< sequence (replicate n getLine)