#K56477. Calculate Plant Height Growth

    ID: 30207 Type: Default 1000ms 256MiB

Calculate Plant Height Growth

Calculate Plant Height Growth

You are given a plant with an initial height h0. The plant grows in a unique pattern: on odd days it grows by b centimeters, and on even days it grows by a centimeters. Given the number of days d, your task is to calculate the final height of the plant.

The growth pattern can be described by the following formula:

\[ \text{Height} = h_0 + \sum_{i=1}^{d} g(i), \quad \text{where}\quad g(i)=\begin{cases} b, & \text{if } i\equiv1\; (\text{mod }2)\\ a, & \text{if } i\equiv0\; (\text{mod }2) \end{cases} \]

Read the input, compute the height after d days for each test case, and print the result.

inputFormat

The first line contains an integer T which denotes the number of test cases. Each of the following T lines contains four space-separated integers: h0, a, b, and d. Here, h0 is the initial height of the plant, a is the growth in centimeters on even days, b is the growth in centimeters on odd days, and d is the number of days.

outputFormat

For each test case, output the final height of the plant after d days on a new line.

## sample
2
10 2 3 5
20 1 2 4
23

26

</p>