import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val s = for(i<-1 to n) yield {
      val l = readLine.split(" ").map(_.toInt)
      val x = l(0)*l(2)+l(1)*l(3)
      val y = (l(0)*(if(l(2)<5) 5 else l(2)) + l(1) * (if(l(3)<2) 2 else l(3)))*0.8
      if(x<y) x.toInt else y.toInt
    }
    println(s.mkString("\n"))
  }
}