Minimum Value Assigned
Submissions: 350   Accuracy:

16.85%

  Difficulty: Easy   Marks: 2

There is a student who wants to assign a value to an array of N integers. He has to assign at least value of 1 to every number. For every two integer numbers at adjacent positions, the one with the higher integral value should be assigned a higher value. He wants to assign the least/minimum amount of values in total. find the minimum value in total assigned to the integers.

Input
The first line of the input contains an interger T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. The first line of each test case contains an integer N denoting the size of the array.The second line of each test case contain N space separated integers.

Output

Output the desired result corresponding to each test case in a separate line. 

Constraints 
1 <= T <= 100
1 <= N <= 100
1 <= A[i] <= 10^5

Example
Input
3
4
1 2 3 4
3
2 4 4
5
2 1 3 2 4

Output
10
4
8

Explanation: 
First test case:
First number is assigned a value = 1. Second number is at adjacent position to first number and has higher integral value. So, it should be assigned with higher value. So, he assigned second number a value of 2. Similarily he assigned third and fourth number, values of 3 and 4 respectively.  
Therefore, in total, 1+2+3+4 =10

Second test case:
First number is assigned a value of 1. Since second number is greater than than the first number, he assigned a value of 2. Third number is equal to second number. So, it can be assigned a lower value. So, assigned a value of 1.
hence 1+2+1 = 4

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

Contributor: Amit Khandelwal
Author: AdityaChatterjee


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.