#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,a) for(int i=(int)0;i<(int)a;++i) #define pb push_back #define eb emplace_back using ll=long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 50; template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; ll p,q,r,a,b,c; bool C(ll mid){ ll x=(mid+p-1)/p; ll y=(mid+q-1)/q; ll z=(mid+r-1)/r; return (x<=a&&y<=a+b&&z<=a+b+c); } bool C2(ll mid){ ll x=(mid+p-1)/p; ll y=(mid+q-1)/q; ll z=(mid+r-1)/r; return (x>=a&&y>=a+b&&z>=a+b+c); } void solve(){ cin>>p>>q>>r; cin>>a>>b>>c; ll l=1,r=INF; while(r-l>1){ ll mid=(l+r)/2; if(C(mid))l=mid; else r=mid; } ll maxv=l; l=0;r=INF; while(r-l>1){ ll mid=(l+r)/2; if(C2(mid))r=mid; else l=mid; } ll minv=r; if(minv>maxv||minv<1)cout<<-1<<"\n"; else cout<