main = sol . fmap get . tail . lines <$> getContents >>= print

get = fmap read . words

sol = f (1,1)

f (t,a) [] = t+a
f (t,a) ([t',a']:ps) = f (m*t',m*a') ps where
  m = 1 + max ((t-1) `div` t') ((a-1) `div` a')