#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    while(n--){
        int pp,bp,pc,bc,mini,mi;
        cin >> bp >> pp >> bc >> pc;
        mini = bp * bc + pp * pc;
        mi = (bp * max(bc,5) + pp * max(pc,2)) * .8;
        cout << min(mini,mi) << endl;
    }
}