import sys
input = sys.stdin.readline
A = int(input())
A_lst = list(map(int, input().split()))
B = int(input())
B_lst = list(map(int, input().split()))
def divide(x, y):
r = x % y
while r != 0:
x = y
y = r
r = x % y
return y
ans = 1
for i in range(A):
for j in range(B):
div = divide(A_lst[i], B_lst[j])
ans *= div
A_lst[i] = A_lst[i] // div
B_lst[j] = B_lst[j] // div
print(A_lst, B_lst)
if ans >= 100000000:
ans = str(ans)
ans = ans[len(ans)-9:]
print(ans)
3
2 3 4
2
2 4