Jason wants to orz Waymo! To achieve this, he can use the following operations:
1. Type "orz" in $$$A$$$ seconds.
2. Copy all the text in $$$B$$$ seconds.
3. Paste all the copied text in $$$C$$$ seconds.
Since Jason is in a hurry, please help him minimize the amount of time he spends to orz Waymo at least $$$N$$$ times.
Each test contains multiple test cases. The first line of input contains a single integer $$$T$$$ ($$$1 \le T \le 10$$$) — the number of test cases.
Each test case contains one line, with four positive integers $$$A$$$, $$$B$$$, $$$C$$$, and $$$N$$$ ($$$1 \le A,B,C \le 10^6, 1 \le N \le 10^9$$$).
—
Tests in subtasks are numbered from $$$1 - 20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-2$$$ satisfy $$$N \le 2000$$$.
Tests $$$3-6$$$ satisfy $$$N \le 5 \cdot 10^5$$$.
Tests $$$7-12$$$ satisfy $$$N \le 10^7$$$.
The remaining tests do not satisfy any additional constraints.
For each test case, output a single integer — the minimum amount of time to type "orz" at least $$$N$$$ times.
41 1 1 201 2 3 1431 4 3 8903 20 7 650
9 29 51 156
In the test case of the sample test, it is optimal to type orz 3 times, then copy, paste, copy, paste, paste, paste.
—
Problem Idea: jay_jayjay
Problem Preparation: jay_jayjay
Occurrences: Novice K, Advanced E
| Name |
|---|


