#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); auto [AU, AL] = []() { int n; cin >> n; ll AU; cin >> AU; ll AL = 1; rep(i,n-1) { ll x; cin >> x; AL *= x; } return make_pair(AU, AL); }(); auto [BU, BL] = []() { int n; cin >> n; vector B(n); rep(i,n) cin >> B[i]; if(n == 1) return make_pair(B[0], 1LL); ll BU = B[n - 2], BL = B[n - 1]; for(int i = n - 3; i >= 0; i--) { swap(BU, BL); BU *= B[i]; } return make_pair(BU, BL); }(); ll CU = AU * BL, CL = AL * BU; ll G = gcd(CU, CL); CU /= G, CL /= G; if((abs(CU) / CU) * (abs(CL) / CL) == -1) { CU = -abs(CU); CL = +abs(CL); } cout << CU << " " << CL << endl; }