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**

I**nput**

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

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.

makeitdonesolo | 64 |

ShubhamJain18 | 64 |

Bishnu Dev Panda | 54 |

DanishBansal | 50 |

abhithakur588 | 50 |

Bishnu Dev Panda | 777 |

yk12 | 512 |

okayboss | 490 |

DevMittal | 472 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.