C. Even Larger
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

An array is called good if, for every subarray$$$^{\text{∗}}$$$ of length at least $$$2$$$, the sum of the elements at even indices (with respect to the original array) is greater than or equal to the sum of the elements at odd indices. Array indexing starts from $$$1$$$.

For example, the arrays $$$[3,8,4,4]$$$ and $$$[2,3,1,4,2]$$$ are good. The array $$$[0,2,4,1]$$$ is not because, in the subarray $$$[2,4,1]$$$, the elements at even indices in the original array are $$$2$$$ (index $$$2$$$) and $$$1$$$ (index $$$4$$$), while the only element at an odd index is $$$4$$$ (index $$$3$$$). Since $$$2 + 1 \lt 4$$$, the condition does not hold for this subarray.

You are given an array of $$$n$$$ non-negative integers $$$a_1,a_2,\ldots,a_n$$$. In one operation, you can decrease any element in the array by $$$1$$$, but all elements must remain non-negative. Your task is to find the minimum number of operations needed to make the array $$$a$$$ good. It can be proved that it is possible to make the array good using a finite number of operations.

$$$^{\text{∗}}$$$An array $$$b$$$ is a subarray of an array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the array $$$a$$$.

The second line of each test case contains $$$n$$$ non-negative integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, output a single integer in a new line — the minimum number of operations needed to make the array $$$a$$$ good.

Example
Input
8
4
3 8 4 4
4
0 2 3 5
2
3 1
5
2 3 1 4 2
4
0 2 4 1
5
3 1 4 5 1
11
3 0 5 4 4 5 3 0 3 4 1
12
410748345 10753674 975233308 193331255 893457280 279719251 704970985 412553354 801228787 44181004 1000000000 3829103
Output
0
1
2
0
3
6
14
4450984776
Note

In the first test case, the array $$$a$$$ is already good, so the answer is $$$0$$$. Below are the checks for each subarray:

SubarrayEven Index SumOdd Index SumCondition met?
$$$[3,8]$$$$$$8$$$$$$3$$$Yes
$$$[8,4]$$$$$$8$$$$$$4$$$Yes
$$$[4,4]$$$$$$4$$$$$$4$$$Yes
$$$[3,8,4]$$$$$$8$$$$$$3+4=7$$$Yes
$$$[8,4,4]$$$$$$8+4 = 12$$$$$$4$$$Yes
$$$[3,8,4,4]$$$$$$8+4=12$$$$$$3 + 4 = 7$$$Yes

In the second test case, the array $$$a$$$ is not good:

SubarrayEven Index SumOdd Index SumCondition met?
$$$[0,2]$$$$$$2$$$$$$0$$$Yes
$$$[2,3]$$$$$$2$$$$$$3$$$No
$$$[3,5]$$$$$$5$$$$$$3$$$Yes
$$$[0,2,3]$$$$$$2$$$$$$0+3=3$$$No
$$$[2,3,5]$$$$$$2 + 5 = 7$$$$$$3$$$Yes
$$$[0,2,3,5]$$$$$$2+5 = 7$$$$$$0+3 = 3$$$Yes

However, if we perform an operation on index $$$3$$$, the array becomes $$$[0,2,2,5]$$$ and is good now:

SubarrayEven Index SumOdd Index SumCondition met?
$$$[0,2]$$$$$$2$$$$$$0$$$Yes
$$$[2,2]$$$$$$2$$$$$$2$$$Yes
$$$[2,5]$$$$$$5$$$$$$2$$$Yes
$$$[0,2,2]$$$$$$2$$$$$$0+2=2$$$Yes
$$$[2,2,5]$$$$$$2 + 5 = 7$$$$$$2$$$Yes
$$$[0,2,2,5]$$$$$$2+5 = 7$$$$$$0+2 = 2$$$Yes

Therefore, the answer is $$$1$$$.