import math N1 = int(input()) lsA = list(map(int,input().split())) N2 = int(input()) lsB = list(map(int,input().split())) lsc = lsA[0]*lsB[-1] lsp = 1 for i in range(1,N1): lsp *= lsA[i] for i in range(N2-2,-1,-1): lsp *= lsB[i] gcd = math.gcd(lsc, lsp) if lsc*lsp < 0: print(-abs(lsc//gcd),abs(lsp//gcd)) else: print(lsc//gcd,lsp//gcd)