#include<iostream>
#include<string>
#include<cassert>
#include<numeric>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<queue>
#include<unordered_map>
#include<tuple>
#include<deque>
#include<functional>
#include<iterator>
#include<array>
#include<forward_list>
using namespace std;
#include<iostream>
#include<cstdio>
#define MAXN 1000001
typedef long long ll;
ll getmaxv(int N,int maxn,ll S1,ll V1,ll S2,ll V2)
{
ll maxv=0;
for(int i=0;i<=maxn;++i)
{
ll value=ll(i)*V1+(N-i*S1)/S2*V2;
if(value>maxv)
{
maxv=value;
}
}
return maxv;
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t;
scanf("%d",&t);
for(int kase=1;kase<=t;++kase)
{
ll N,S1,V1,S2,V2;
scanf("%lld%lld%lld%lld%lld",&N,&S1,&V1,&S2,&V2);
ll maxv=0;
int minNdivS=min(N/S1,N/S2);
if(S1<minNdivS||S2<minNdivS)
{
if(S2*V1<S1*V2)
{
maxv=getmaxv(N,S2,S1,V1,S2,V2);
}
else
{
maxv=getmaxv(N,S1,S2,V2,S1,V1);
}
}
else
{
if(N/S1<N/S2)
{
maxv=getmaxv(N,N/S1,S1,V1,S2,V2);
}
else
{
maxv=getmaxv(N,N/S2,S2,V2,S1,V1);
}
}
printf("Case #%d: %lld\n",kase,maxv);
}
}
09-02
146
11-04
296