import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== public void solve() { int N1 = Integer.parseInt(sc.next()); int[] A = new int[N1]; for (int i = 0; i < N1; i++) { A[i] = Integer.parseInt(sc.next()); } int N2 = Integer.parseInt(sc.next()); int[] B = new int[N2]; for (int i = 0; i < N2; i++) { B[i] = Integer.parseInt(sc.next()); } long A1 = A[0]; for (int i = 1; i < N2; i++) { A1 *= (long)B[i]; } long B1 = B[0]; for (int i = 1; i < N1; i++) { B1 *= (long)A[i]; } // out.println("A1 = " + A1 + " B1 = " + B1); long AX = Math.abs(A1); long BX = Math.abs(B1); for (long i = 2; i <= Math.max(AX, BX); i++) { while(true) { if(AX % i == 0 && BX % i == 0) { AX /= i; BX /= i; // out.println(" " + i + " で割った  AX = " + AX + " BX = " + BX); } else break; } if(AX < i || BX < i) break; } if((A1 > 0 && B1 > 0) || (A1 < 0 && B1 < 0)) { out.println(AX + " " + BX); } else { out.println(-AX + " " + BX); } } }