#include<iostream>
using namespace std;

int calc(int x,int y,int b,int p){
  if(b<5)b=5;
  if(p<2)p=2;
  return (x*b + y*p)*0.8;
}

int main(){
  int n;
  cin>>n;
  int x,y,b,p;
  for (int i = 0; i < n; i++){
    cin>>x>>y>>b>>p;
    cout << min(calc(x,y,b,p),x*b + y*p) << endl;   
  }
  return 0;
}