Minimum Time
Submissions: 1343   Accuracy:

33.42%

  Difficulty: Medium   Marks: 4

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
Author: Ayush Govil 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



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


to report an issue on this page.