#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,x,y,b,p,result;
  cin >> n;
  for(int i = 0; i < n;i++){
    cin >> x >> y >> b >> p;
    cout << min(x*b+y*p, (x*max(b,5)+y*max(p,2))*4/5) << endl;
  }

  return 0;
}