n1 = int(input()) a = [ int(v) for v in input().split() ] n2 = int(input()) b = [ int(v) for v in input().split() ] x = a[0] y = b[0] def gcd(a,b): a, b = abs(a), abs(b) if a < b: a, b = b, a while b >= 1: a, b = b, a % b return a for i in range(n2-1): if i % 2 == 0: x *= b[i+1] else: y *= b[i+1] for i in range(n1-1): y *= a[i+1] if y < 0: x, y = -x, -y x, y = x // gcd(x,y), y // gcd(x,y) print(x, y)