BETA

Difficulty Level: Medium

Submissions: 365 Accuracy:

29.86%

Minimum Time
     

You need to write N same characters on a screen and each time you can insert a character, delete the last character and copy and paste all written characters i.e. after copy operation count of total written character will become twice. Now you are given time for insertion, deletion and copying. You need to output minimum time to write N characters on the screen using these operations.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer N denoting the number of same characters to write on screen. The next line contains time for insertion, deletion and copying respectively.

Output:
Print the minimum to write N characters on the screen.

Constraints:
1<=T<=100
1<=N<=100
1<=insert,remove,copy<=N

Example:
Input:

2
9
1 2 1
10
2 5 4

Output:
5
14

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.