题目
#include<bits/stdc++.h>
using namespace std;
int t,bread,beef,chicken,h,c,money,w,m;
bool flag;
inline void the_beef(int &beef){
if(bread==beef*2){
cout<<beef*h<<endl;
}else if(bread>beef*2){
bread-=beef*2;
money+=beef*h;
beef=0;
}else{
for(int i=1;i<=beef;i++){
if(i*2==bread){
bread=0;
money+=i*h;
beef=0;
flag=true;
}
}
}
}
inline void the_chicken(int &chicken){
if(bread==chicken*2){
cout<<chicken*c<<endl;
}else if(bread>chicken*2){
bread-=chicken*2;
money+=chicken*c;
chicken=0;
}else{
for(int i=1;i<=chicken;i++){
if(i*2==bread){
bread=0;
money+=i*c;
chicken=0;
flag=true;
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>t;
for(int i=1;i<=t;i++){
cin>>bread>>beef>>chicken>>h>>c;
bread-=bread%2;
if(bread<=0){
cout<<0<<endl;
continue;
}
w=min(beef,chicken);
m=w;
beef-=w;
chicken-=w;
h>c?the_beef(beef):the_chicken(chicken);
if(bread==0){
continue;
}
if(bread==w*2){
if(h>c){
cout<<money+w*h<<endl;
continue;
}else{
cout<<money+m*c<<endl;
continue;
}
}else if(bread>w*2){
if(bread>w*4){
cout<<money+w*h+m*c<<endl;
continue;
}else{
if(h>c){
bread-=w*2;
money+=w*h;
w=0;
for(int i=1;i<=m;i++){
if(i*2==bread){
bread=0;
money+=i*c;
chicken=0;
flag=true;
}
}
}else{
bread-=m*2;
money+=m*h;
m=0;
for(int i=1;i<=w;i++){
if(i*2==bread){
bread=0;
money+=i*c;
chicken=0;
flag=true;
}
}
}
}
}
cout<<money<<endl;
}
return 0;
}