import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

void main(){

    int n = readln().chomp().to!int;
    for(int i=0;i<n;i++){
	int[] s = split(readln()).to!(int[]);
	int res = s[0] * s[2] + s[1] * s[3];
	if(s[2] >= 5 && s[3] >= 2)  res = to!int(to!real(res*0.8));
	else if(s[2] >= 5) res = min(res, to!int(0.8*(s[0]*s[2]+s[1]*2)));
	else if(s[3] >= 2) res = min(res, to!int(0.8*(s[0]*5+s[1]*s[3])));
	else res = min(res, to!int(0.8*(s[0]*5 + s[1]*2)));
	writeln(res);
    }

}