402915: GYM100947 C Rotate It !!
Description
Dzy and Fox have a sequence A consisting of N numbers [A1...AN]. Dzy starts by taking the first number, then Fox takes the second number, then Dzy takes the third number and so on, they continue taking turns until all of the N numbers are taken. The player with the highest sum of numbers wins.
Since Dzy is your dear friend, you decided to rotate the sequence (you may rotate it as many times as you like) in order to maximize Dzy's sum of numbers.
Rotation is defined as removing the first element from the beginning of the sequence and adding it to the end of the sequence.
So given the sequence A , you have to help Dzy and let him achieve the maximum possible sum.
InputThe first line containts a single integer T, the number of test cases.
Then T testcases are given as follows :
The first line of each testcase contains a single integer N (1 ≤ n ≤ 104).
The second line of each testcase contains N space-separated integers [A1...AN],the elements of the sequence A (1 ≤ i ≤ n) ( - 109 ≤ Ai ≤ 109).
OutputOutput T lines , The answer for each testcase which is the maximum achievable sum by Dzy if you help him.
ExamplesInput1Output
5
1 5 3 2 4
12Note
Consider all 5 rotations of the sequence:
1 5 3 2 4 (Dzy score = 1 + 3 + 4 = 8)
5 3 2 4 1 (Dzy score = 8)
3 2 4 1 5 (Dzy score = 12)
2 4 1 5 3 (Dzy score = 6)
4 1 5 3 2 (Dzy score = 11)