Chefland has 77 days in a week. Chef is very conscious about his work done during the week.

There are two ways he can spend his energy during the week. The first way is to do xx units of work every day and the second way is to do yy (>x>x) units of work for the first dd (<7<7) days and to do zz (<x<x) units of work thereafter since he will get tired of working more in the initial few days.

Find the maximum amount of work he can do during the week if he is free to choose either of the two strategies.

**For the work from home Internship Programs **: Click here to apply now

### Input

- The first line contains an integer TT, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, four integers dd, xx, yy, zz.

### Output

For each testcase, output in a single line the answer to the problem.

### Constraints

- 1≤T≤5⋅1031≤T≤5⋅103
- 1≤d<71≤d<7
- 1≤z<x<y≤181≤z<x<y≤18

### Subtasks

**Subtask #1 (100 points):** Original constraints

### Sample Input

```
3
1 2 3 1
6 2 3 1
1 2 8 1
```

### Sample Output

```
14
19
14
```

### Explanation

**Test Case 11:** Using the first strategy, Chef does 2⋅7=142⋅7=14 units of work and using the second strategy Chef does 3⋅1+1⋅6=93⋅1+1⋅6=9 units of work. So the maximum amount of work that Chef can do is max(14,9)=14max(14,9)=14 units by using the first strategy.

**Test Case 22:** Using the first strategy, Chef does 2⋅7=142⋅7=14 units of work and using the second strategy Chef does 3⋅6+1⋅1=193⋅6+1⋅1=19 units of work. So the maximum amount of work that Chef can do is max(14,19)=19max(14,19)=19 units by using the second strategy.

**SOLUTION**

```
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
ll test;
cin>>test;
while(test--){
ll d,x,y,z;
cin>>d>>x>>y>>z;
cout<<max((x*7),((y*d)+(z*(7-d))))<<endl;
}
}
```

- INTERVIEW QUESTIONS | OS | FOR BEGINNER TO ADVANCED 2021
- Interview Questions | OOPS | For Beginner to Advanced 2021
- Interview Questions | DBMS | For Beginner to Advanced 2021
- PayPal is hiring Interns || Apply now
- Top 20 C++ Tricks for Competitive Programming that you should know

*Read more post Here*