Loading...
Shawarma Cravings
Time: 1 s
Memory: 125 MB
Tanvir is on a quest to satisfy his shawarma cravings at the campus canteen. The canteen sells shawarmas at a regular price of \(p\) per item. However, they have two special offers:
  • Offer 1: If a customer buys one shawarma, they receive a discount of \(a\) on the price.
  • Offer 2: If a customer buys two shawarmas at once, they receive a discount of \(b\) on the price of two shawarmas.
However, Tanvir can only buy one or two shawarmas at a time.
You are given the regular price \(p\) of each shawarma and the total number of shawarmas \(n\)  Tanvir wants to buy. Help him calculate the minimum total price he needs to pay to satisfy his shawarma cravings.
Input
The first line contains a single integer \(t\) — the number of test cases.
The first line of each test case contains four integers \(n, p, a, b\) — described in the statement.
Constraint
\(1 \leq t \leq 10^5\)
\(1 \leq n \leq 10^5\)
\(2 \leq p \leq 10^4\)
\(1 \leq a < p\)
\(1 \leq b < 2 \cdot p\) 
It is guaranteed that the sum of \(n\) over all test cases doesn't exceed \(2 \cdot 10^5\).
Output
For each test case, print a single integer — described in the statement.
Examples
Input
Output
2
3 20 3 5
5 20 3 10
51
77
Notes
In the first testcase of the sample, buying \(3\) times individually you will get \((20-3)*3=17*3=51\).
Problem Info
Problem ID 266
Time Limit 1000 ms
Memory Limit 128000 KB
Moderators amirhozaifa , fahimcp495
Statistics
Submit
You need to Login or Registration for submit your solution