n = gets.to_i
n.times do
    x, y, b, p = gets.split.map(&:to_i)
    ans = (x + y) * 6
    (0..6).each do |i|
        (0..6).each do |j|
            next if i < b or j < p
            total = x * i + y * j
            total = total / 50 * 40 if i >= 5 and j >= 2
            ans = [ans, total].min
        end
    end
    puts ans
end