import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  solve <$> replicateM n (getl $ toTpl . wrds toInt) >>= print

toTpl :: [Int] -> (Int,Int)
toTpl [x,y] = (x,y)

solve :: [(Int,Int)] -> Int
solve xs = g $ foldl f (head xs) (tail xs)
  where
    f :: (Int,Int) -> (Int, Int) -> (Int,Int)
    f (x,y) (t,a)
      | x <= t && y <= a = (t,a)
      | otherwise = (b * t, b * a)
      where
        b = max (if x `mod` t == 0 then x `div` t else x `div` t + 1) (if y `mod` a == 0 then y `div` a else y `div` a + 1)
    g (x,y) = x + y

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine
