#include <iostream>
using namespace std;

int main() {
	int N = 0;
	int x, y, b, p;
	int max = 0;
	int wari = 0;

	int i = 0;

	cin >> N;

	while (1) {
		cin >> x;
		cin >> y;
		cin >> b;
		cin >> p;

		max = ((x * b) + (y * p));

		if (b < 5){
			b = 5;
		}

		if (p < 2){
			p = 2;
		}


		wari = ((x * b) + (y * p)) * 0.8;

		if (max < wari) {
			cout << max << "\n";
		} else {
			cout << wari << "\n";
		}

		i++;

		if(i == N) {
			return 0;
		}
	}
}