#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	for (int z = 0; z < n; z++) {
		int x, y, o, p;
		double sum = 0;
		cin >> x >> y >> o >> p;
		int h = o*x + p*y;
		sum = min(h, (max(5, o)*x+max(2, p)*y)*4/5);
		cout << sum << endl;
	}
}