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

int main(){
	int n;
	cin>>n;
	for(;n--;){
		int x,y,b,p;
		cin>>x>>y>>b>>p;
		cout<<min((x*max(5,b)+y*max(2,p))*8/10, x*b+y*p)<<endl;
	}
}