#include <iostream>
#include <algorithm>
using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  int i;
  for (i = 0; i < n; i++) {
    int x, y, b, p;
    cin >> x >> y >> b >> p;
    cout << min((x * b + y * p), (int)((double)(x * max(b, 5) + y * max(p, 2)) * 0.8)) << endl;
  }
  return 0;
}

