try : from math import gcd except Exception as error : from fractions import gcd x = y = 1 N = int(input()) A = list(map(int,input().split())) M = int(input()) B = list(map(int,input().split())) for i, a in enumerate(A) : if i == 0 : x *= a else : y *= a for i, b in enumerate(B) : if i == 0 : y *= b else : x *= b z = gcd(x, y) ans1, ans2 = x//z, y//z if ans2 < 0 : ans1 *= -1 ans2 *= -1 print(ans1, ans2)