input() a,*A=map(int,input().split()) input() b,*B=map(int,input().split()) for i in A:b*=i for i in B:a*=i x=a y=b while b:a,b=b,a%b print(x//a,y//a)