#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        double x,y,b,p;
        cin>>x>>y>>b>>p;
        int num1=x*b+y*p;
        int num2=(x*max(b,5.0)+(y*max(p,2.0)))*(8.0/10);
        cout<<min(num1,num2)<<endl;
    }
}
