Rahul is a geek he loves to play with array. He was very much bored so he asked you to solve array by selecting a pair of adjacent integers and remove the larger one of these two. This decreases the array size by 1. Cost of this operation will be equal to the smaller of them. Your task is to find out minimum sum of costs of operations needed to convert the array into a single element.
First line of input contains a single integer T denoting the number of test cases. First line of each test case starts with an integer N denoting the size of the array A. Next line of input contains N space separated integers, where the ith integer denotes the value Ai.
For each test case, print the minimum cost required to transform array into single element.
4 2 5
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.