#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));} pair solve(const vector& v, const vector& w){ if(v.size()==0){ return make_pair(1LL,1LL); } if(v.size()==1){ ll g = gcd(v[0], w[0]); return make_pair(v[0]/g,w[0]/g); } ll x = v[v.size()-1] * w[0]; vector vv, ww; rep(i,v.size()-2) vv.push_back(v[i]); vv[0] *= w[1]; REP(i,2,w.size()) ww.push_back(w[i]); ww[0] *= v[v.size()-2]; pair ret = solve(vv, ww); ret.second *= x; ll g = gcd(ret.first, ret.second); return make_pair(ret.first/g, ret.second/g); } int main(){ int n, m; vector v, w; cin >> n; rep(i,n){ ll a; cin >> a; v.push_back(a); } cin >> m; rep(i,m){ ll a; cin >> a; w.push_back(a); } if(n<10) rep(i,10-n) v.push_back(1); if(m<10) rep(i,10-m) w.push_back(1); pair ret = solve(v,w); if(ret.first < 0 && ret.second < 0){ ret.first *= -1; ret.second *= -1; } else if(ret.second < 0){ ret.first *= -1; ret.second *= -1; } cout << ret.first << " " << ret.second << endl; return 0; }