#K93927. Minimum Travel Cost

    ID: 38528 Type: Default 1000ms 256MiB

Minimum Travel Cost

Minimum Travel Cost

Alice wants to travel a distance (D) and has three modes of transportation to choose from:

  • Walking: costs \(W\) per unit distance, total cost \(W \times D\).
  • Biking: costs \(B\) per unit distance, total cost \(B \times D\).
  • Cab: has a fixed cost of \(C\), regardless of the distance.

Your task is to compute the minimum cost for each test case by selecting the cheapest option among walking, biking, and taking a cab.

For example, if (W = 2), (B = 3), (C = 20) and (D = 10), the options are:

  • Walking cost: (2 \times 10 = 20)
  • Biking cost: (3 \times 10 = 30)
  • Cab cost: (20)

Thus, the minimum cost is (20).

inputFormat

The first line contains an integer (T) denoting the number of test cases. Each of the following (T) lines contains four space-separated integers: (W), (B), (C) and (D), where:

  • \(W\): cost per unit distance for walking
  • \(B\): cost per unit distance for biking
  • \(C\): fixed cost for taking a cab
  • \(D\): total distance to travel

outputFormat

For each test case, output the minimum travel cost on a new line.## sample

5
2 3 20 10
1 5 15 5
3 2 8 4
2 3 30 1
5 4 25 6
20

5 8 2 24

</p>