ans ([0]:_) = []
ans ([n]:x) =
  let r = drop n x
      d = map (\ [a,b] -> (a,b) ) $ take n x
      l = foldr1 lcm $ map snd d
      a = map (\ (a,b) -> a * l `div` b) d
      g = foldr1 gcd a
      a'= map (\ aa -> aa `div` g) a
      l'= foldr1 lcm a'
      aa= map (\ aa -> l' `div` aa) a'
  in
    aa++ans r

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ print o
  