n = gets.to_i
ans = []

n.times do
  x, y, b, p = gets.split.map(&:to_i)
  normal_sum = x * b + y * p

  if b >= 5 && p >= 2
    ans << normal_sum * 0.8
  else
    discount_sum = ([5, b].max * x + [2, p].max * y) * 0.8
    ans << [normal_sum, discount_sum].min
  end
end

ans.each do |a|
  p a.to_i
end

