// Problem: No.2386 Udon Coupon (Easy)No.2386 乌冬面优惠券 (简易) // Contest: yukicoder // URL: https://yukicoder.me/problems/no/2386 // Memory Limit: 512 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include using namespace std; typedef long long ll; const int N=2e5+10; const int INF=0x3f3f3f3f; const int mod=1e9+7; #define x first #define y second ll ksm(ll n,ll p,int mod){ int ans=1; while(p){ if(p&1) ans=(ans*n)%mod; n=(n*n)%mod;p>>=1; } return ans; } ll inv(ll b,ll c=mod) {return ksm(b,c-2,c);} class Num{ public: ll num; Num(ll x) {num=(x%mod+mod)%mod;} Num operator+(Num p) {return Num(num+p.num);} Num operator-(Num p) {return Num(num-p.num);} Num operator*(Num p) {return Num(num*p.num);} Num operator/(Num p) {return Num(num*inv(p.num));} Num operator=(Num p) {this->num=p.num;return *this;} friend ll get(Num p) {return p.num;} }; void solve() { ll n; cin>>n; vector> ve; for(int i=0;i<3;i++) { ll a,b; cin>>a>>b; ve.push_back({a,b}); } sort(ve.begin(),ve.end(),[](auto p1,auto p2){ return p1.y*p2.x>=p1.x*p2.y; }); ll ans=0; for(int i=1;i<3;i++) { ans+=n/ve[i-1].x*ve[i-1].y; n%=ve[i-1].x; ans+=n/ve[i].x*ve[i].y; n%=ve[i].x; } cout<>T; while(T--) { solve(); } return 0; }