n = int(input()) A = list(map(int,input().split())) m = int(input()) B = list(map(int,input().split())) def gcd(a,b): while True: r = a % b a = b b = r if r == 0: return a si = A[0] for b in B[1:]: si *= b bo = B[0] for a in A[1:]: bo *= a d = gcd(abs(si),abs(bo)) si //= d bo //= d if bo < 0: si *= -1 bo *= -1 print(si,bo)