Sumin likes deques, so his teacher gave him a cool deque game. The game works based on an array , and is played as follows:
- There will initially be a variable and a deque containing just the element .
- Sumin will go through the array elements, starting with the 1st one and ending at the nth one. At the element Gigel must choose one of two ways to progress the game:
- add to T the first element of the deque, then put at the front of the deque (that is )
- add to T the last element of the deque, then put at the back of the deque (that is )
After the element is processed, the score of the game will be equal to the current value of T. Grigoutz wants to minimize this final score T but he is unsure if he received the minimum score that is possible. Can you help him calculate it?
Task
Sumin asks you to write a program which given and the number of minutes to write each of the essays will print the minimum value of after the operations.
Input
The first line contains an integer () the number of test cases. Then follows the description of the test cases.
The first line contains a single integer () the length of the array.
The second line of each test case contains integers () - the elements of the array.
It is guaranteed that the sum of the values of over all test cases does not exceed .
Output
For each test case, you have to print a single integer - the minimum value of
Examples
stdin
3
2
1 2
5
9 3 6 5 9
8
5 6 4 8 3 1 0 10
stdout
0
14
19
Example description
For the first test case, Sumin will go for the first choice, resulting in and the deque containing . After this, he will go with the second choice, adding to , and the deque contains in this order.
For the second test case, Sumin will go for the first choice, resulting in and the deque containing . After this, he will go with the second choice, adding to , and the deque contains in this order. Third choice is for the back, and deque is . Next is the back once again, resulting in and the deque is . Final choice is still on the back side of the deque, resulting in and the deque being .