#include<iostream>
using namespace std;
int main()
{
	while(0);
	
	int n;
	cin>>n;
	for(int i=0;i<n;i+=1){
		int x,y,b,p,ans,ano,t=5,s=2;
		cin>>x>>y>>b>>p;
		if(b>t)t=b;
		if(p>s)s=p;
		ans=x*b+y*p;
		ano=4*(x*t+y*s)/5;
		if(ans>ano)ans=ano;
		
		cout<<ans<<endl;
	}
}