#P1430. 序列取数

序列取数

Description

Given an integer sequence of length nn (n1000)(n \le 1000), A and B take numbers in turns (A goes first). On each turn, a player may take one or more numbers from either the left end or the right end of the sequence, but not from both ends in the same turn. After all numbers have been taken, each player sums the numbers they took as their score. Assume A and B are both clever enough to play optimally and maximize their own score. Find A's final score.

Input Format

The first line contains a positive integer TT, indicating there are TT testcases (T100)(T \le 100). Then follow TT lines. In each line, the first number is nn, followed by nn integers that form the given sequence.

Output Format

Output TT lines, each containing one integer, which is A's score.

2
1 -1
2 1 2
-1
3

Hint

Translated by ChatGPT 5