import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n1 = sc.nextInt(); ArrayDeque mothers = new ArrayDeque<>(); ArrayDeque children = new ArrayDeque<>(); int x = sc.nextInt(); boolean isMPlus = true; boolean isCPlus = true; if (x < 0) { isCPlus ^= true; x *= -1; } children.add(x); for (int i = 1; i < n1; i++) { int y = sc.nextInt(); if (y < 0) { isMPlus ^= true; y *= -1; } mothers.add(y); } int n2 = sc.nextInt(); for (int i = 0; i < n2; i++) { int y = sc.nextInt(); if (i % 2 == 0) { if (y < 0) { isMPlus ^= true; y *= -1; } mothers.add(y); } else { if (y < 0) { isCPlus ^= true; y *= -1; } children.add(y); } } long mother = 1; long child = 1; ArrayDeque next = new ArrayDeque<>(); while (mothers.size() > 0) { int m = mothers.poll(); while (children.size() > 0) { int c = children.poll(); int gcd = getGCD(m, c); m /= gcd; c /= gcd; if (c != 1) { next.add(c); } if (m == 1) { break; } } if (m != 1) { mother *= m; } children.addAll(next); next.clear(); } while (children.size() > 0) { child *= children.poll(); } if (isMPlus ^ isCPlus) { child *= -1; } System.out.println(child + " " + mother); } static int getGCD(int x, int y) { if (x % y == 0) { return y; } else { return getGCD(y, x % y); } } }