#include <iostream>
using namespace std;

int main() {
	int N;
	cin>>N;
	int x,y,b,p;
	int total;
	for (int i=0;i<N;++i){
		cin >>x>>y>>b>>p;
		total=x*b+y*p;
		if(b>=5&&p>=2)total=total*4/5;

		if(b<5&&p>=2)total=min(total,((5*x+p*y)*4)/5);
		if(b>=5&&p<2)total=min(total,((b*x+2*y)*4)/5);
		if(b<5&&p<2)total=min(total,((5*x+2*y)*4)/5);
		cout<<total<<endl;
	}
	return 0;
}