#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int x,y,b,p;
		cin>>x>>y>>b>>p;
		int mid=x*b+y*p;
		int over=(x*5+y*2+x*max(b-5,0)+y*max(p-2,0))*8/10;
		if(b>=5 && p>=2){
			cout<<mid*8/10<<endl;
		}else if(over<mid){
			cout<<over<<endl;
		}else{
			cout<<mid<<endl;
		}

	}
	return 0;

}