#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;
		cout << min(x*b + y*p, x*max(5, b) * 4 / 5 + y*max(p, 2) * 4 / 5) << endl;
	}
}