You are given a sequence consisting of integers. Find the minimum possible total cost of performing the following operation exactly times so that only one element remains.
The input is given in the following format.
For each test case, print the minimum total cost on its own line, in input order.
In the first test case, merging costs and leaves . The next merge costs , for a total of . Starting with the last pair gives the same total. In the second case, merging from the left costs and then , totaling . The third case needs one operation: one copy of remains and the cost is .
The first line contains the number of test cases . Each test case has the following format.
The first line of each test case contains the sequence length . The second line contains , separated by spaces.
| 3 | 19 |
|
| 4 | 39 | No additional constraints. |
In the first case, each of the three operations costs , so the total is . In the second case, the smaller value remains, and the larger value is the cost.