n_a = gets.to_i A = gets.split.map(&:to_i) n_b = gets.to_i B = gets.split.map(&:to_i) A << 1 B << 1 def dfs(i, r, nums) if i + 1 < nums.size dfs(i + 1, Rational(r, nums[i]), nums) else Rational(r, nums[i]) end end r = Rational(dfs(1, A[0], A), dfs(1, B[0], B)) puts [r.numerator, r.denominator].join(' ')