import math def main(): minus = 0 n_1 = int(input()) a = list(map(int,input().split())) a_top = a[0] a_bottom = a[1] for i in range(2,n_1): a_bottom *= a[i] if a_top < 0: a_top *= -1 minus += 1 if a_bottom < 0: a_bottom *= -1 minus += 1 gcd_1 = math.gcd(a_top,a_bottom) a_top //= gcd_1 a_bottom //= gcd_1 n_2 = int(input()) b = list(map(int, input().split())) b_top = b[0] b_bottom = b[1] for i in range(2, n_2): b_bottom *= b[i] if b_top < 0: minus += 1 b_top *= -1 if b_bottom < 0: minus += 1 b_bottom *= -1 gcd_b = math.gcd(b_top, b_bottom) b_top //= gcd_b b_bottom //= gcd_b ans_top = a_top * b_bottom ans_bottom = b_top * a_bottom ans_gcd = math.gcd(ans_top,ans_bottom) ans_top = ans_top // ans_gcd ans_bottom = ans_bottom // ans_gcd print(ans_top * pow(-1,minus), ans_bottom) main()