#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
	int n,x,y,b,p;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&x,&y,&b,&p);
		printf("%d\n",min(x*b+y*p,(x*(b<5?5:b)+y*(p<2?2:p))*4/5));
	}
}