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

int main()
{
    int n;
    int x, y;
    int b, p;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        cin >> b >> p;

        int a1 = x * b + y * p;
        int a2 = (a1 + max(0, 5-b)*x + max(0, 2-p)*y) / 10 * 8;

        cout << min(a1, a2) << endl;
    }

    return 0;
}

