spoj#WAYHOME. The Bridge to Home

The Bridge to Home

Late in the night, a group of people are approaching home after an exciting adventure in the wilderness. However, as a last challenge on their long and tiresome fare, they have to cross a small bridge over a raging river.

The bridge is so narrow and slippery that the group decides only to let a maximum of two people walk on it at any given time. Also, the person or pair who is walking on the bridge, must carry the single light that the group possesses.

The group asks you to determine, given the amounts of time that each person takes to cross the bridge, the minimum total amount of time it'll take the entire group to cross. Notice that, when two people walk on the bridge at the same time, their crossing time is determined by the slower walker.

Input

First line: The number of testcases C.

Next C lines: The number of people in the group N, followed by N sorted integers Ai. Ai is the crossing time of the i-th person.

0 ≤ C ≤ 100; 1 ≤ N ≤ 1000; 0 ≤ Ai ≤ 1000.

Output

For each testcase, write the minimum total amount of time it'll take the group to pass.

Example

Input:
4
1 1
2 1 2
3 1 1 1
4 1 2 4 8
Output:
1
2
3
15

In the third test case, the people can cross the bridge in the following way:

  1. The first two people walk over the bridge, taking 1 time unit.
  2. One person walks back over the bridge, with the light, taking 1 time unit.
  3. The two people, now on the left, cross the bridge, taking 1 time unit.