from math import gcd n1 = int(input()) alst = list(map(int, input().split())) n2 = int(input()) blst = list(map(int, input().split())) u = alst[0] d = blst[0] for num in alst[1:]: d *= num for num in blst[1:]: u *= num tmp = gcd(d, u) print(u // tmp, d // tmp)