#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int x,y,a,b;
	int xx,yy,aa,bb;
	int o,p;
	int i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x>>y>>a>>b;
		if(a>=5&&b>=2){
			x*=0.8;
			y*=0.8;
			cout<<x*a+y*b<<endl;
		}
		else{
			o=x*a+y*b;
			x*=0.8;
			y*=0.8;
			if(a<5)	a+=5-a;
			if(b<2)	b+=2-b;
			p=x*a+y*b;
			//cout<<o<<" "<<p<<endl;
			cout<<min(o,p)<<endl;
		}
	}
			
	return 0;
}
