def gcd(x, y): if y == 0: return x return gcd(y, x % y) n1 = int(input()) a = list(map(int, input().split())) n2 = int(input()) b = list(map(int, input().split())) bunbo = b[0] bunsi = a[0] for i in a[1:]: bunbo = bunbo * i for i in b[1:]: bunsi = bunsi * i g = gcd(bunsi, bunbo) print(int(bunsi / g), int(bunbo / g))