#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = (int)1e9;

int main(){
  int n;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    int x,y,b,p,ans=INF,calc;
    scanf("%d%d%d%d",&x,&y,&b,&p);

    for(int i=b;i<=6;i++){
      for(int j=p;j<=6;j++){
	calc = i*x+j*y;
	if(i>=5 && j>=2) calc = calc*4/5;
	ans = min(ans,calc);
      }
    }

    cout << ans << endl;
  }

  return 0;
}