#include<iostream>
#include<algorithm>
#define INF ( 1 << 28 )
using namespace std;
int N,x,y,b,p;
int solve(int n,int p){
  if(n > 6 || p > 6) return INF;
  if(n > 4 && p > 1 ) return (x*n + y*p) * 0.8;
  return min( x*n + y*p, min(solve(n+1,p),solve(n,p+1)));
}
int main(){
  cin >> N;
  while(N--){
    cin >> x >> y >> b >> p;
    cout << solve(b,p) << endl;
  }
}