open Batteries

let solve (a, b) line =
  Scanf.sscanf line "%d %d" @@ fun x y ->
  let ratio = max ((a-1) / x+1) ((b-1) / y+1) in
  (x*ratio, y*ratio)

let () =
  IO.lines_of stdin
  |> Enum.skip 1
  |> Enum.fold solve (1, 1)
  |> fun (x, y) -> Int.print stdout (x + y)
