Sequence Merging

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a sequence a1,a2,,ana_1, a_2, \dots, a_n. In one step you can pick two adjacent numbers aia_i and ai+1a_{i+1} and replace both of them with the single number max(ai,ai+1)\max(a_i, a_{i+1}). That step costs max(ai,ai+1)\max(a_i, a_{i+1}). Each step makes the sequence one shorter, so after n1n-1 steps a single number is left.

Given the sequence, compute the minimum total cost of reducing it to length 1.

Input

The first line contains the number of test cases TT (1T1000001 \le T \le 100000).

Each test case takes two lines. The first line contains the length of the sequence NN (2N50002 \le N \le 5000). The second line contains the NN integers of the sequence, separated by single spaces. Every integer is between 11 and 100000100000 inclusive.

Output

For each test case, print one line in the format Case #x: R, where xx is the test case number starting from 1 and RR is the minimum cost of reducing that sequence to length 1.