#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 sum = x * b + y * p;
		if(b < 5)
			b = 5;
		if(p < 2)
			p = 2;
		cout << min(sum ,int((x * b + y * p) * 0.8)) << endl;
	}
	return 0;
}
