n_a = gets.to_i A = gets.split.map(&:to_i) n_b = gets.to_i B = gets.split.map(&:to_i) a = A[1..-1].map(&:abs).inject(:*) b = B[1..-1].map(&:abs).inject(:*) n = [a, b].inject(:lcm) a = A[1..-1].inject(:*) b = B[1..-1].inject(:*) r = Rational(A[0] * n / a, B[0] * n / b) puts [r.numerator, r.denominator].join(' ')