### main

n = gets.strip.to_i

n.times do
  x, y, bn, pn = gets.strip.split(' ').map{|s| s.to_i}

  if bn >= 5 && pn >= 2
    cost = (x * bn + y * pn) * 4 / 5
  else
    cost0 = x * bn + y * pn
    bn1 = [bn, 5].max
    pn1 = [pn, 2].max
    cost1 = (x * bn1 + y * pn1) * 4 / 5
    cost = [cost0, cost1].min
  end
  puts cost
end