import std.stdio;
import std.algorithm;
import std.string;
import std.conv;

void main() {
	auto N = to!int(readln.chomp);
	foreach (i; 0..N) {
		auto input = readln.split.map!(to!int);
		if (input[2] >= 5 && input[3] >= 2) {
			writeln((input[0] * input[2] + input[1] * input[3]) * 4 / 5);
		} else if (input[2] >= 5) {
			int a = input[0] * input[2] + input[1] * input[3];
			int b = (input[0] * input[2] + input[1] * 2) * 4 / 5;
			writeln(min(a, b));
		} else if (input[3] >= 2) {
			int a = input[0] * input[2] + input[1] * input[3];
			int b = (input[0] * 5 + input[1] * input[3]) * 4 / 5;
			writeln(min(a, b));
		} else {
			int a = input[0] * input[2] + input[1] * input[3];
			int b = (input[0] * 5 + input[1] * 2) * 4 / 5;
			writeln(min(a, b));
		}
	}
}