Jonathan typically doesn't eat lunch. Today, he is helping Thornhill's Tech Crew to earn some profit, and to do this, he is selling burgers!
There are 2 types of burgers that Jonathan can make, which are:
Beef: 2 buns, 1 meat patty
Vegetarian: 2 buns, 1 veggie patty
You have buns, meat patties and veggie patties. You sell one beef burger for dollars and one veggie burger for dollars. What is the maximum profit you can make?
You have queries you need to answer.
Input Specification
The first line of input will contain , .
The next line of input will contain the first line of each query , , and , , respectively.
The second line of each query will contain and , .
Output Specification
For each query output an integer on a separate line, which should be the maximum profit you can achieve.
Sample Input 1
5
2 4 1
7 2
5 5 1
3 9
5 2 4
2 8
4 3 1
6 4
3 3 1
10 1
Sample Output 1
7
12
16
12
10
Comments