def gcd(a,b): if b==0:return a return gcd(b,a%b) N1 = int(input()) A = list(map(int,input().split())) N2 = int(input()) B = list(map(int,input().split())) a = A[0] for i in range(1,N2): a = a*B[i] b = B[0] for i in range(1,N1): b = b*A[i] d = gcd(a,b) if a*b>0: print(a//d,b//d) else: print(-abs(a//d),abs(b//d))