#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,x,y,b,p;
	cin>>n;
	rep(i,n){
		cin>>x>>y>>b>>p;
		int ans=x*b+y*p;
		if(b>=5 && p>=2){
			ans=ans*0.8;
		}else if(b>=5){
			ans=min(ans,(x*b+y*(p/2+1)*2)*4/5);
		}else if(p>=2){
			ans=min(ans,(x*(b/5+1)*5+y*p)*4/5);
		}
		ans=(int)min(ans,((x*(b/5+1)*5+y*(p/2+1)*2)*4/5));
		cout<<ans<<endl;
	}
	return 0;
}