#include <iostream>

using namespace std;

int main(void){
	int n;cin>>n;
	for(int i=0;i<n;++i){
		int x,y,b,p,ans;
		cin>>x>>y>>b>>p;
		ans = x*b+y*p;
		int fare = (x*((b>5)?b:5)+y*((p>2)?p:2))*8/10;
		ans=min(fare,ans);
		cout<<ans<<endl;
	}
	return 0;
}