#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n,x,y,b,p;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>y>>b>>p;
		cout<<min(x*b+y*p,(max(b,5)*x+max(p,2)*y)*4/5)<<endl;
	}
	return 0;
}