#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int kk = 0; kk < n; kk++)
    {
        int x, y, b, p;
        cin >> x >> y >> b >> p;
        int ans = x * b + y * p;
        for (int i = 1; i <= 5; i++)
        {
            int tmp = ((5 * x + 2 * y) * i + max(0, b - 5 * i) * x + max(0, p - 2 * i) * y) * 0.8;
            ans = min(ans, tmp);
        }
        cout << ans << endl;
    }
}
