You are given an array $a$ consisting of $n$ integers. Indices of the array start from zero (i. e. the first element is $a_0$, the second one is $a_1$, and so on).

You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $a$ with borders $l$ and $r$ is $a[l; r] = a_l, a_{l + 1}, \dots, a_{r}$.

Your task is to reverse such a subarray that the sum of elements on even positions of the resulting array is maximized (i. e. the sum of elements $a_0, a_2, \dots, a_{2k}$ for integer $k = \lfloor\frac{n-1}{2}\rfloor$ should be maximum possible).

You have to answer $t$ independent test cases.


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $a$. The second line of the test case contains $n$ integers $a_0, a_1, \dots, a_{n-1}$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer on the separate line — the maximum possible sum of elements on even positions after reversing at most one subarray (continuous subsegment) of $a$.


-----Example-----
Input
4
8
1 7 3 4 7 6 2 9
5
1 2 1 2 1
10
7 8 4 5 7 6 8 9 7 3
4
3 1 2 1

Output
26
5
37
5

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Divide and conquer

Implementation

Greedy algorithms
Skill types: Dynamic programming

Greedy algorithms

Starter code:

Solutions:
def maxSubArraySum(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_ending_here < 0:
			max_ending_here = 0
		elif max_so_far < max_ending_here:
			max_so_far = max_ending_here
	return max_so_far
for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()][:n]
	evensum = 0
	for i in range(0, len(l), 2):
		evensum += l[i]
	(x, y) = ([], [])
	for i in range(1, len(l), 2):
		x.append(l[i] - l[i - 1])
		if i + 1 < len(l):
			y.append(l[i] - l[i + 1])
	p = maxSubArraySum(x, len(x))
	q = maxSubArraySum(y, len(y))
	add = max(p, q)
	if add > 0:
		evensum += add
	print(evensum)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = sum(a[::2])
	total = 0
	maxn = 0
	for i in range(0, n - 1, 2):
		total += a[i + 1] - a[i]
		maxn = max(total, maxn)
		if total < 0:
			total = 0
	total2 = 0
	for i in range(1, n - 1, 2):
		total2 += a[i] - a[i + 1]
		maxn = max(total2, maxn)
		if total2 < 0:
			total2 = 0
	print(ans + maxn)


def max_subarray(numbers):
	best_sum = 0
	current_sum = 0
	for x in numbers:
		current_sum = max(0, current_sum + x)
		best_sum = max(best_sum, current_sum)
	return best_sum
t = int(input())
for _ in range(t):
	l = int(input())
	a = list(map(int, input().split()))
	z = max_subarray(map(lambda x: x[1] - x[0], zip(a[::2], a[1::2])))
	y = max_subarray(map(lambda x: x[1] - x[0], zip(a[2::2], a[1::2])))
	print(sum(a[::2]) + max(z, y))


from sys import stdin, stdout
import sys
from math import *

def kedane(a, n):
	ans = 0
	curr = 0
	for i in range(n):
		curr += a[i]
		if curr > ans:
			ans = max(ans, curr)
		elif curr <= 0:
			curr = 0
	return ans
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	a = []
	for i in range(1, n):
		if i % 2 == 1:
			a.append(ar[i] - ar[i - 1])
	b = []
	for i in range(2, n):
		if i % 2 == 0:
			b.append(ar[i - 1] - ar[i])
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += ar[i]
	print(max(ans, ans + kedane(a, len(a)), ans + kedane(b, len(b))))


w = int(input())
for _ in range(w):
	n = int(input())
	A = list(map(int, input().split(' ')))
	(e, o) = (0, 1)
	(L, R) = [-1, -1]
	MAX = 0
	total = 0
	(l, r) = (0, 1)
	while e < n and o < n:
		diff = A[e + 1] - A[e]
		total += diff
		if total < 0:
			total = 0
			e += 2
			o += 2
			(l, r) = (e, o)
		elif total >= MAX:
			MAX = total
			(L, R) = (l, o)
			e += 2
			o += 2
		else:
			e += 2
			o += 2
	if L == -1:
		count1 = 0
		for i in range(0, n, 2):
			count1 += A[i]
	else:
		count1 = 0
		for i in range(0, L, 2):
			count1 += A[i]
		for i in range(R + 1, n, 2):
			count1 += A[i]
		for i in range(L + 1, R + 1, 2):
			count1 += A[i]
	(e, o) = (1, 2)
	(L, R) = [-1, -1]
	MAX = 0
	total = 0
	(l, r) = (1, 2)
	while e < n and o < n:
		diff = A[e] - A[e + 1]
		total += diff
		if total < 0:
			total = 0
			e += 2
			o += 2
			(l, r) = (e, o)
		elif total >= MAX:
			MAX = total
			(L, R) = (l, o)
			e += 2
			o += 2
		else:
			e += 2
			o += 2
	if L == -1:
		count2 = 0
		for i in range(0, n, 2):
			count2 += A[i]
	else:
		count2 = 0
		for i in range(0, L, 2):
			count2 += A[i]
		for i in range(R + 2, n, 2):
			count2 += A[i]
		for i in range(L, R + 1, 2):
			count2 += A[i]
	print(max(count1, count2))


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))

def mss(a):
	res = 0
	msf = 0
	for i in a:
		msf = max(msf + i, 0)
		res = max(msf, res)
	return res
for _ in range(r()):
	n = r()
	a = rl()
	curr = 0
	for i in range(0, n, 2):
		curr += a[i]
	b = []
	c = []
	for i in range(0, n - 1, 2):
		b.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		c.append(a[i] - a[i + 1])
	print(curr + max(0, mss(b), mss(c)))


def max_subarray_sum(arr):
	max_so_far = max_ending_here = 0
	for i in arr:
		max_ending_here += i
		max_so_far = max(max_so_far, max_ending_here)
		max_ending_here = max(max_ending_here, 0)
	return max_so_far

def max_on_even(arr):
	n = len(arr)
	default_sum = sum(arr[::2])
	v1 = list()
	v2 = list()
	for i in range(0, n - 1, 2):
		v1.append(arr[i + 1] - arr[i])
	for i in range(1, n - 1, 2):
		v2.append(arr[i] - arr[i + 1])
	v1_res = max_subarray_sum(v1)
	v2_res = max_subarray_sum(v2)
	delta = max(0, v1_res, v2_res)
	return default_sum + delta
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = max_on_even(arr)
	print(res)


def find_max_sum(a):
	if len(a) == 1:
		return 0
	if len(a) == 2:
		return a[0] + a[1]
	if len(a) == 3:
		return max(a[0] + a[1], a[1] + a[2])
	n = int(len(a) / 2)
	l_max = find_max_sum(a[0:n])
	r_max = find_max_sum(a[n:len(a)])
	lsum_odd = a[n - 1]
	lsum_even = float('-inf')
	rsum_odd = a[n]
	rsum_even = float('-inf')
	x = 0
	for i in range(0, n):
		x += a[n - 1 - i]
		if i % 2 == 0 and x > lsum_odd:
			lsum_odd = x
		if i % 2 != 0 and x > lsum_even:
			lsum_even = x
	x = 0
	for i in range(0, len(a) - n):
		x += a[n + i]
		if i % 2 == 0 and x > rsum_odd:
			rsum_odd = x
		if i % 2 != 0 and x > rsum_even:
			rsum_even = x
	max_sum = max(l_max, r_max, lsum_odd + rsum_odd, lsum_even + rsum_even)
	return max_sum

def find_max_sum_evenpos(a):
	sum = 0
	b = []
	for i in range(0, len(a)):
		if i % 2 == 0:
			sum += a[i]
			b.append(-a[i])
		else:
			b.append(a[i])
	return max(sum, sum + find_max_sum(b))
n = int(input())
for i in range(0, n):
	a = []
	input()
	s = input().split(' ')
	for j in s:
		a.append(int(j))
	print(find_max_sum_evenpos(a))


def kadane(pref):
	if pref:
		mxg = mxl = pref[0]
		pref.pop(0)
		for p in pref:
			mxl = max(p, p + mxl)
			if mxl > mxg:
				mxg = mxl
		if mxg < 0:
			mxg = 0
		return mxg
	return 0
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	evesum = 0
	pref = []
	suf = []
	for i in range(0, n, 2):
		evesum += arr[i]
		if i + 1 < n:
			pref.append(arr[i + 1] - arr[i])
		if i > 1:
			suf.append(arr[i - 1] - arr[i])
	extra = max(kadane(pref), kadane(suf))
	print(evesum + extra)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	se = [0]
	for i in range(n):
		if i % 2 == 0:
			se.append(se[-1] + a[i])
	ans = se[-1]
	tmp = 0
	A = 0
	for i in range(0, n - 1, 2):
		tmp += a[i + 1] - a[i]
		A = max(A, tmp)
		if tmp < 0:
			tmp = 0
	tmp = 0
	B = 0
	for i in range(1, n - 1, 2):
		tmp += a[i] - a[i + 1]
		B = max(B, tmp)
		if tmp < 0:
			tmp = 0
	ans += max(A, B, 0)
	print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []

def best_subarray(array):
	m = len(array)
	best_including_last_using_first_i_elems = [0]
	for i in range(m):
		option1 = array[i] + best_including_last_using_first_i_elems[-1]
		option2 = array[i]
		choice = max(option1, option2)
		final = max(0, choice)
		best_including_last_using_first_i_elems.append(final)
	return max(best_including_last_using_first_i_elems)
for _ in range(testCases):
	n = int(input())
	arr = input_split()
	if n % 2 == 0:
		diff = [arr[2 * i + 1] - arr[2 * i] for i in range(n // 2)]
		diff2 = [arr[2 * i + 1] - arr[2 * i + 2] for i in range(n // 2 - 1)]
	else:
		diff = [arr[2 * i + 1] - arr[2 * i] for i in range(n // 2)]
		diff2 = [arr[2 * i + 1] - arr[2 * i + 2] for i in range(n // 2)]
	even_ind = [arr[i] for i in range(n) if i % 2 == 0]
	odd_ind = [arr[i] for i in range(n) if i % 2 == 1]
	temp = sum(even_ind)
	ans = temp + max(best_subarray(diff), best_subarray(diff2))
	answers.append(ans)
print(*answers, sep='\n')


import math
from sys import maxsize as maxint

def maxSubArraySum(a):
	max_so_far = -maxint - 1
	max_ending_here = 0
	i = 0
	while i < len(a) - 1:
		dif = a[i] - a[i + 1]
		if i % 2 == 0:
			dif = a[i + 1] - a[i]
		max_ending_here = max_ending_here + dif
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
		i += 2
	i = 1
	max_ending_here = 0
	while i < len(a) - 1:
		dif = a[i] - a[i + 1]
		if i % 2 == 0:
			dif = a[i + 1] - a[i]
		max_ending_here = max_ending_here + dif
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
		i += 2
	return max_so_far
for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	s = sum(array[::2])
	a = maxSubArraySum(array)
	print(max(s, s + a))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():

	def maxeven(vals, n):
		if n < 2:
			return 0
		else:
			m1 = 0
			s1 = 0
			for s in range(1, n, 2):
				if s1 + vals[s] + vals[s - 1] > 0:
					s1 += vals[s] + vals[s - 1]
					if s1 > m1:
						m1 = s1
				else:
					s1 = 0
			m2 = 0
			s2 = 0
			for s in range(2, n, 2):
				if s2 + vals[s] + vals[s - 1] > 0:
					s2 += vals[s] + vals[s - 1]
					if s2 > m2:
						m2 = s2
				else:
					s2 = 0
			return max(m1, m2)
	testcases = int(input())
	for j in range(testcases):
		n = int(input())
		vals = list(map(int, input().split()))
		ans = 0
		for s in range(0, n, 2):
			ans += vals[s]
			vals[s] = -vals[s]
		add = maxeven(vals, n)
		if add > 0:
			print(ans + add)
		else:
			print(ans)
main()


t = int(input())
while t > 0:
	(n, a) = (int(input()), list(map(int, input().split())))
	(mx_n, mx) = (0, 0)
	for i in range(0, n - 1, 2):
		mx_n += a[i + 1] - a[i]
		mx = max(mx_n, mx)
		mx_n = max(0, mx_n)
	mx_n = 0
	for i in range(1, n - 1, 2):
		mx_n += a[i] - a[i + 1]
		mx = max(mx_n, mx)
		mx_n = max(0, mx_n)
	even = sum((a[i] for i in range(n) if i % 2 == 0))
	print(even + mx)
	t -= 1


def kadene(A):
	max_g = 0
	max_c = 0
	for i in range(len(A)):
		max_c = max(A[i], max_c + A[i])
		if max_c > max_g:
			max_g = max_c
	return max_g

def answer(n, A):
	if n == 1:
		return A[0]
	dp = [0] * (n // 2)
	count = 0
	s = 0
	for i in range(1, n, 2):
		dp[count] = A[i] - A[i - 1]
		count += 1
		s += A[i - 1]
	dp1 = [0] * (n // 2)
	count = 0
	for i in range(1, n, 2):
		if i + 1 < n:
			dp1[count] = A[i] - A[i + 1]
			count += 1
	k1 = kadene(dp)
	k2 = kadene(dp1)
	if n % 2 != 0:
		s += A[-1]
	return s + max(k1, k2)
t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	print(answer(n, A))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += a[i]
	l = []
	m = []
	c = 0
	for i in range(1, n - 1, 2):
		l.append(a[i] - a[i + 1])
	for i in range(0, n - 1, 2):
		m.append(a[i + 1] - a[i])
	c = 0
	ma = 0
	for i in range(len(l)):
		c += l[i]
		ma = max(ma, c)
		if c < 0:
			c = 0
	c = 0
	for i in range(len(m)):
		c += m[i]
		ma = max(ma, c)
		if c < 0:
			c = 0
	print(ans + ma)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	even = 0
	for i in range(0, n, 2):
		even += a[i]
	x = [0] * n
	p = [0] * n
	for i in range(0, n - 1, 2):
		x[i // 2] = a[i + 1] - a[i]
	for i in range(1, n - 1, 2):
		p[i // 2] = a[i] - a[i + 1]
	y = x[0]
	ans = x[0]
	for i in x[1:]:
		y = max(y + i, i)
		ans = max(ans, y)
	y = p[0]
	ans = max(ans, y)
	for i in p[1:]:
		y = max(y + i, i)
		ans = max(ans, y)
	print(ans + even)


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	diff = []

	def maxsub(a, size):
		max_so_far = 0
		max_ending_here = 0
		for i in range(0, size):
			max_ending_here = max_ending_here + a[i]
			if max_ending_here < 0:
				max_ending_here = 0
			elif max_so_far < max_ending_here:
				max_so_far = max_ending_here
		return max(0, max_so_far)
	for j in range(0, n, 2):
		if j != n - 1:
			diff.append(a[j + 1] - a[j])
	s = 0
	for i in range(0, n, 2):
		s += a[i]
	z = maxsub(diff, len(diff))
	x = 0
	diff = []
	for j in range(1, n, 2):
		if j != n - 1:
			diff.append(a[j] - a[j + 1])
	x = maxsub(diff, len(diff))
	print(s + max(z, x))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	summ = sum(num[::2])
	cs = 0
	mx = 0
	for i in range(0, n - n % 2, 2):
		cs = max(0, cs + num[i + 1] - num[i])
		mx = max(mx, cs)
	cs = 0
	for k in range(1, n - int(n % 2 == 0), 2):
		cs = max(0, cs + num[k] - num[k + 1])
		mx = max(mx, cs)
	print(summ + mx)


t = int(input())
for u in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = [a[i] - a[i - 1] for i in range(1, n, 2)]
	b.append(0)
	m1 = [b[0]]
	for i in range(1, b.__len__()):
		if m1[i - 1] >= 0:
			m1.append(m1[i - 1] + b[i])
		else:
			m1.append(b[i])
	ans = sum([a[i] for i in range(n) if i - 1 & 1]) + max(max(m1), 0)
	c = [a[i - 1] - a[i] for i in range(2, n, 2)]
	c.append(0)
	m2 = [c[0]]
	for i in range(1, c.__len__()):
		if m2[i - 1] >= 0:
			m2.append(m2[i - 1] + c[i])
		else:
			m2.append(c[i])
	ans = max(ans, sum([a[i] for i in range(n) if i - 1 & 1]) + max(max(m2), 0))
	print(ans)


def solve(n, a):
	if n == 1:
		return a[0]
	elif n == 2:
		return max(a)
	even_sum = sum((a[i] for i in range(0, n, 2)))
	(la, lb) = ([], [])
	for i in range(n - 1):
		if i % 2 == 0:
			la.append(-a[i] + a[i + 1])
		else:
			lb.append(a[i] - a[i + 1])
	(ta, tb) = ([la[0]], [lb[0]])
	for e in la[1:]:
		ta.append(max(e, ta[-1] + e))
	for e in lb[1:]:
		tb.append(max(e, tb[-1] + e))
	return even_sum + max(max(ta), max(tb), 0)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	m = 0
	evens = 0
	for i in range(0, n - 1, 2):
		evens += arr[i + 1] - arr[i]
		evens = max(0, evens)
		m = max(evens, m)
	odds = 0
	for i in range(1, n - 1, 2):
		odds += arr[i] - arr[i + 1]
		odds = max(0, odds)
		m = max(odds, m)
	print(sum(arr[::2]) + m)


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	current_sum = 0
	for i in range(0, n, 2):
		current_sum += nums[i]
	limite_par = n // 2 - 1
	if n % 2 == 0:
		limite_impar = limite_par - 1
	else:
		limite_impar = limite_par
	ganancias_pares = []
	ganancias_impares = []
	max_eve_sum = max_odd_sum = 0
	current_eve_sum = current_odd_sum = 0
	for i in range(limite_par + 1):
		voltear = nums[2 * i + 1] - nums[2 * i]
		current_eve_sum += voltear
		if current_eve_sum < voltear:
			current_eve_sum = voltear
		max_eve_sum = max(max_eve_sum, current_eve_sum)
	for i in range(limite_impar + 1):
		voltear = nums[2 * i + 1] - nums[2 * i + 2]
		current_odd_sum += voltear
		if current_odd_sum < voltear:
			current_odd_sum = voltear
		max_odd_sum = max(max_odd_sum, current_odd_sum)
	print(current_sum + max(max_odd_sum, max_eve_sum))


def maxsum(a):
	if len(a) == 0:
		return 0
	ans = a[0]
	notmaxisum = 0
	maxisum = 0
	for i in range(len(a)):
		notmaxisum += a[i]
		d = notmaxisum - maxisum
		if d > ans:
			ans = d
		maxisum = min(maxisum, notmaxisum)
	return ans

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	c = [a[i] - a[i + 1] for i in range(1, n - 1, 2)]
	d = [a[i] - a[i - 1] for i in range(1, n, 2)]
	xc = maxsum(c)
	xd = maxsum(d)
	x = max(xc, xd)
	count = 0
	for i in range(n):
		if i % 2 == 0:
			count += a[i]
	print(count + max(x, 0))
t = int(input())
for _ in range(t):
	solve()


def solh(arr, neg=False):
	sm = 0
	mxend = 0
	i = 1
	while i < len(arr):
		sm += (-1 if neg else 1) * (arr[i] - arr[i - 1])
		mxend = max(mxend, sm)
		if sm < 0:
			sm = 0
		i += 2
	return mxend

def solve():
	n = int(input())
	arr = [int(v) for v in input().split()]
	i = 0
	sm = 0
	while i < n:
		sm += arr[i]
		i += 2
	print(max(solh(arr), solh(arr[1:], True)) + sm)
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')

def maxEvenLenSum(a, n):
	ans1 = 0
	this = 0
	l = 0
	for i in a:
		this += i
		l += 1
		if this < 0 and l % 2 == 0:
			this = 0
			l = 0
		if l % 2 == 0:
			ans1 = max(ans1, this)
	ans2 = 0
	this = 0
	l = 0
	for i in a:
		this += i
		l += 1
		if this < 0:
			this = 0
			l = 0
		if l % 2 == 0:
			ans2 = max(ans2, this)
	return max(ans1, ans2)
for _ in range(int(input())):
	n = int(input())
	a = int_array()
	ans = sum([a[i] for i in range(0, n, 2)])
	for i in range(0, n, 2):
		a[i] *= -1
	ans = ans + maxEvenLenSum(a, n)
	print(ans)


z = int(input())
for h in range(z):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	if n == 1:
		print(l[0])
	else:
		x = l[1] - l[0]
		if n > 2:
			y = l[1] - l[2]
			if y < 0:
				y = 0
			a.append(y)
		if x < 0:
			x = 0
		a.append(x)
		i = 3
		while i < n:
			if x < 0:
				x = 0
			if y < 0:
				y = 0
			x += l[i] - l[i - 1]
			if i < n - 1:
				y += l[i] - l[i + 1]
			a.append(x)
			a.append(y)
			i += 2
		b = []
		i = 0
		while i < n:
			b.append(l[i])
			i += 2
		print(sum(b) + max(a))


for s in [*open(0)][2::2]:
	l = [*map(int, s.split())]
	x = sum(l[::2])
	n = len(l)
	l = [(2 * (i & 1) - 1) * l[i] for i in range(n)]
	min_e = min_o = 0
	sm = 0
	a = 0
	for i in range(n):
		sm += l[i]
		if 1 & i:
			a = max(a, sm - min_o)
			min_o = min(sm, min_o)
		else:
			a = max(a, sm - min_e)
			min_e = min(sm, min_e)
	print(max(x, x + a))


def subsolve(a):
	c = 0
	m = 0
	for i in a:
		c += i
		if c < 0:
			c = 0
		m = max(m, c)
	return m

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(0, n, 2):
		s += a[i]
	u = subsolve([a[i] - a[i - 1] for i in range(1, n, 2)])
	v = subsolve([a[i - 1] - a[i] for i in range(2, n, 2)])
	print(max(u, v) + s)
t = int(input())
for _ in range(t):
	solve()


from collections import defaultdict
Q = int(input())
for _ in range(Q):
	n = int(input())
	a = list(map(int, input().split()))
	ev = a[0:n:2]
	od = a[1:n:2]
	sa = [0]
	tmp = 0
	for i in range(len(od)):
		tmp = max(0, tmp + od[i] - ev[i])
		sa.append(tmp)
	if len(od) > len(ev):
		tmp += od[i + 1]
		sa.append(tmp)
	tmp = 0
	for i in range(len(ev) - 1):
		tmp = max(0, tmp + od[i] - ev[i + 1])
		sa.append(tmp)
	print(sum(ev) + max(sa))


def maxSubArraySum(a, size):
	max_so_far = -100000000
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	lilef = []
	lirig = []
	for i in range(1, len(li), 2):
		lilef.append(li[i] - li[i - 1])
		if i + 1 < len(li):
			lirig.append(li[i] - li[i + 1])
	sumi = 0
	for i in range(0, len(li), 2):
		sumi = sumi + li[i]
	maxans = max(maxSubArraySum(lirig, len(lirig)), maxSubArraySum(lilef, len(lilef)))
	if maxans > 0:
		print(sumi + maxans)
	else:
		print(sumi)


tt = int(input())
for loop in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	e = [0]
	o = [0]
	for i in range(n):
		if i % 2 == 0:
			e.append(e[-1] + a[i])
			o.append(o[-1])
		else:
			e.append(e[-1])
			o.append(o[-1] + a[i])
	eo = []
	for i in range(n + 1):
		eo.append(o[i] - e[i])
	nmin = float('inf')
	ans = 0
	for i in range(0, n + 1, 2):
		ans = max(ans, eo[i] - nmin)
		nmin = min(nmin, eo[i])
	nmin = float('inf')
	for i in range(1, n + 1, 2):
		ans = max(ans, eo[i] - nmin)
		nmin = min(nmin, eo[i])
	ori = 0
	for i in range(0, n, 2):
		ori += a[i]
	print(ori + ans)


import math

def solve():
	n = int(input())
	tot = 0
	l = list(map(int, input().split()))
	for i in range(n):
		if i % 2 == 0:
			tot += l[i]
			l[i] *= -1
	for i in range(1, n):
		l[i] += l[i - 1]
	mx = [0] * n
	for i in range(n - 1, -1, -1):
		mx[i] = l[i]
		if i + 2 < n:
			mx[i] = max(mx[i], mx[i + 2])
	ans = tot
	if n > 1:
		ans = max(ans, tot + mx[1])
	for i in range(n):
		if i + 2 < n:
			ans = max(ans, tot + mx[i + 2] - l[i])
	print(ans)
	return
t = 1
t = int(input())
while t > 0:
	t -= 1
	solve()


import sys
from collections import deque
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = sum(a[::2])
	ans = d
	for i in range(n):
		if i % 2 == 0:
			a[i] = -a[i]
	(l, r) = (0, 1)
	curr_sum = 0
	while r < n:
		curr_sum += a[r] + a[r - 1]
		r += 2
		if curr_sum < 0:
			while curr_sum < 0 or l < r - 3:
				curr_sum -= a[l] + a[l + 1]
				l += 2
		ans = max(ans, d + curr_sum)
	(l, r) = (1, 2)
	curr_sum = 0
	while r < n:
		curr_sum += a[r] + a[r - 1]
		r += 2
		if curr_sum < 0:
			while curr_sum < 0 or l < r - 3:
				curr_sum -= a[l] + a[l + 1]
				l += 2
		ans = max(ans, d + curr_sum)
	print(ans)


def summation(v):
	local_max = -1000000000 + 7
	global_max = -1000000000 + 7
	for i in range(len(v)):
		local_max = max(v[i], local_max + v[i])
		global_max = max(local_max, global_max)
	return global_max
testcase = int(input())
for test in range(testcase):
	n = int(input())
	arr = list(map(int, input().split()))
	suma = 0
	for i in range(n):
		if i % 2 == 0:
			suma = suma + arr[i]
	v1 = []
	v2 = []
	for i in range(0, n - 1, 2):
		v1.append(arr[i + 1] - arr[i])
	for i in range(1, n - 1, 2):
		v2.append(arr[i] - arr[i + 1])
	x = summation(v1)
	y = summation(v2)
	m = max(x, y)
	m = max(m, 0)
	print(suma + m)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = 0
	s = a[0]
	d = 0
	m = 0
	for i in range(1, n, 2):
		b += a[i] - a[i - 1]
		if b - m > d:
			d = b - m
		if b < m:
			m = b
	b = m = e = 0
	for i in range(2, n, 2):
		s += a[i]
		b += a[i - 1] - a[i]
		if b - m > e:
			e = b - m
		if b < m:
			m = b
	f = max(d, e)
	print(s + max(f, 0))


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	mx = 0
	cur = 0
	for i in range(0, n - 1, 2):
		cur += lis[i + 1] - lis[i]
		cur = max(0, cur)
		mx = max(cur, mx)
	cur = 0
	for i in range(1, n - 1, 2):
		cur += lis[i] - lis[i + 1]
		cur = max(0, cur)
		mx = max(cur, mx)
	s = 0
	for i in range(0, n, 2):
		s += lis[i]
	print(s + mx)


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	current_su = 0
	for i in range(n):
		if i % 2 == 0:
			current_su += a[i]
	odd_su = 0
	even_su = 0
	pre_odd = [0]
	pre_even = [0]
	for i in range(n - 1):
		switch = a[i + 1 - i % 2] - a[i + i % 2]
		if i % 2 == 1:
			odd_su += switch
			pre_odd.append(odd_su)
		else:
			even_su += switch
			pre_even.append(even_su)
	smallest_odd = 0
	smallest_even = 0
	best = 0
	for i in range(len(pre_odd)):
		val = pre_odd[i]
		best = max(best, val - smallest_odd)
		smallest_odd = min(smallest_odd, val)
	for i in range(len(pre_even)):
		val = pre_even[i]
		best = max(best, val - smallest_even)
		smallest_even = min(smallest_even, val)
	print(current_su + best)


def max_subarray(numbers):
	best_sum = 0
	best_start = best_end = 0
	current_sum = 0
	for (current_end, x) in enumerate(numbers):
		if current_sum <= 0:
			current_start = current_end
			current_sum = x
		else:
			current_sum += x
		if current_sum > best_sum:
			best_sum = current_sum
			best_start = current_start
			best_end = current_end
	return (best_sum, best_start, best_end)
for testcase in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	if len(nums) == 1:
		print(nums[0])
		continue
	elif len(nums) == 2:
		print(max(nums))
		continue
	s = sum(nums[::2])
	diffs = [b - a for (a, b) in zip(nums[::2], nums[1::2])]
	(best_sum, best_start, best_end) = max_subarray(diffs)
	diffs2 = [a - b for (a, b) in zip(nums[1::2], nums[2::2])]
	(best_sum2, best_start, best_end) = max_subarray(diffs2)
	best_sum = max(best_sum, best_sum2)
	print(best_sum + s)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	even_sum = sum(l[::2])
	v1 = []
	v2 = []
	for i in range(1, n - 1, 2):
		v1.append(l[i] - l[i + 1])
	for i in range(0, n - 1, 2):
		v2.append(l[i + 1] - l[i])
	c = 0
	m = 0
	for i in range(len(v1)):
		c += v1[i]
		m = max(m, c)
		if c < 0:
			c = 0
	c = 0
	for i in range(len(v2)):
		c += v2[i]
		m = max(m, c)
		if c < 0:
			c = 0
	print(even_sum + m)


n = int(input())
for _ in range(n):
	n1 = int(input())
	l = list(map(int, input().split()))
	cur = 0
	mx = 0
	for i in range(0, n1 - 1, 2):
		cur += l[i + 1] - l[i]
		cur = max(0, cur)
		mx = max(cur, mx)
	cur = 0
	for i in range(1, n1 - 1, 2):
		cur += l[i] - l[i + 1]
		cur = max(0, cur)
		mx = max(mx, cur)
	sm = 0
	for i in range(0, n1, 2):
		sm += l[i]
	print(sm + mx)


import sys
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right
from collections import deque
from collections import Counter
from itertools import accumulate, combinations, permutations
from heapq import heapify, heappop, heappush
from functools import lru_cache

def input():
	return sys.stdin.readline()[:-1]

def printl(li):
	_ = print(*li, sep='\n') if li else None

def argsort(s, return_sorted=False):
	inds = sorted(range(len(s)), key=lambda k: s[k])
	if return_sorted:
		return (inds, [s[i] for i in inds])
	return inds

def alp2num(c, cap=False):
	return ord(c) - 97 if not cap else ord(c) - 65

def num2alp(i, cap=False):
	return chr(i + 97) if not cap else chr(i + 65)

def matmat(A, B):
	(K, N, M) = (len(B), len(A), len(B[0]))
	return [[sum([A[i][k] * B[k][j] for k in range(K)]) for j in range(M)] for i in range(N)]

def matvec(M, v):
	(N, size) = (len(v), len(M))
	return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]

def T(M):
	(n, m) = (len(M), len(M[0]))
	return [[M[j][i] for j in range(n)] for i in range(m)]

def main():
	mod = 1000000007
	N = int(input())
	A = tuple(map(int, input().split()))
	guu = []
	ki = []
	for (i, a) in enumerate(A):
		if i % 2 == 0:
			guu.append(a)
		else:
			ki.append(a)
	sguu = sum(guu)
	l = []
	for i in range(1, len(guu)):
		l.append(ki[i - 1] - guu[i])
	cmax = 0
	cur = 0
	for li in l:
		cur = max(cur + li, li)
		cmax = max(cmax, cur)
	a1 = cmax + sguu
	l = []
	for i in range(0, min(len(guu), len(ki))):
		l.append(ki[i] - guu[i])
	cmax = 0
	cur = 0
	for li in l:
		cur = max(cur + li, li)
		cmax = max(cmax, cur)
	a2 = cmax + sguu
	print(max(a1, a2))
q = int(input())
for _ in range(q):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		continue
	if n == 2:
		print(max(a))
		continue
	(even, odd) = ([], [])
	for i in range(n):
		if i % 2 == 0:
			even.append(a[i])
		else:
			odd.append(a[i])
	(ans1, ans2) = (0, 0)
	dif1 = []
	for i in range(len(odd)):
		dif1.append(odd[i] - even[i])
	tmp = 0
	for i in range(len(dif1)):
		tmp += dif1[i]
		if ans1 < tmp:
			ans1 = tmp
		if tmp < 0:
			tmp = 0
	dif2 = []
	for i in range(len(even) - 1):
		dif2.append(odd[i] - even[i + 1])
	tmp = 0
	for i in range(len(dif2)):
		tmp += dif2[i]
		if ans2 < tmp:
			ans2 = tmp
		if tmp < 0:
			tmp = 0
	print(sum(even) + max(ans1, ans2))


nb_cases = int(input())
for case in range(nb_cases):
	n = int(input())
	a = [int(x) for x in input().split()]
	dp_pair = []
	dp_impair = []
	for x in range(n - 1):
		if x % 2 == 0:
			dp_pair.append(a[x + 1] - a[x])
		else:
			dp_impair.append(a[x] - a[x + 1])
	p1 = 0
	p2 = 0
	somme = 0
	p_min = -1
	p_max = -1
	somme_max = 0
	while p2 < int(n / 2):
		somme += dp_pair[p2]
		if dp_pair[p2] > 0:
			if somme > somme_max:
				somme_max = somme
				p_min = p1
				p_max = p2
		elif somme <= 0:
			p1 = p2 + 1
			somme = 0
		p2 += 1
	somme_max_pair = somme_max
	p1 = 0
	p2 = 0
	somme = 0
	p_min = -1
	p_max = -1
	somme_max = 0
	while p2 < int((n - 1) / 2):
		somme += dp_impair[p2]
		if dp_impair[p2] > 0:
			if somme > somme_max:
				somme_max = somme
				p_min = p1
				p_max = p2
		elif somme <= 0:
			p1 = p2 + 1
			somme = 0
		p2 += 1
	somme_max_impair = somme_max
	somme_pair = sum([x for x in a[::2]])
	print(somme_pair + max(somme_max_pair, somme_max_impair))


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	a1 = 0
	s = 0
	for j in range(1, n, 2):
		a1 += a[j] - a[j - 1]
		a1 = max(0, a1)
		ans = max(ans, a1)
	a1 = 0
	for j in range(0, n, 2):
		s += a[j]
		if j != 0:
			a1 += a[j - 1] - a[j]
			a1 = max(0, a1)
			ans = max(ans, a1)
	print(s + ans)


import sys
testcase = int(input())
INF = 1 << 60

def input():
	return sys.stdin.readline().rstrip()

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	S = 0
	for i in range(n):
		if i % 2 == 0:
			S += a[i]
	ans = S
	b = [a[i] * (-1) ** (i % 2 + 1) for i in range(n)]
	v = 0
	for i in range(n - 1, -1, -1):
		if i + 1 >= n or i % 2 != 0:
			continue
		v = max(v + b[i] + b[i + 1], 0)
		ans = max(ans, v + S)
	v = 0
	for i in range(n - 1, -1, -1):
		if i + 1 >= n or i % 2 == 0:
			continue
		v = max(v + b[i] + b[i + 1], 0)
		ans = max(ans, v + S)
	print(ans)
	return
for i in range(testcase):
	solve()


import sys
input = sys.stdin.readline

def max_sub_array_sum(a):
	s = temp = 0
	for i in a:
		temp += i
		if temp < 0:
			temp = 0
		s = max(temp, s)
	return s
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	tot = sum([arr[i] for i in range(0, n, 2)])
	even = [arr[i + 1] - arr[i] for i in range(0, n - 1, 2)]
	odd = [arr[i] - arr[i + 1] for i in range(1, n - 1, 2)]
	print(max(tot, tot + max_sub_array_sum(even), tot + max_sub_array_sum(odd)))


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7

class SparseTable:

	def __init__(self, A, func):
		self.N = len(A)
		self.func = func
		h = 0
		while 1 << h <= self.N:
			h += 1
		self.dat = list2d(h, 1 << h, 0)
		self.height = [0] * (self.N + 1)
		for i in range(2, self.N + 1):
			self.height[i] = self.height[i >> 1] + 1
		for i in range(self.N):
			self.dat[0][i] = A[i]
		for i in range(1, h):
			for j in range(self.N):
				self.dat[i][j] = self.func(self.dat[i - 1][j], self.dat[i - 1][min(j + (1 << i - 1), self.N - 1)])

	def get(self, l, r):
		if l >= r:
			raise Exception
		a = self.height[r - l]
		return self.func(self.dat[a][l], self.dat[a][r - (1 << a)])
for _ in range(INT()):
	N = INT()
	A = LIST()
	B1 = []
	B2 = []
	for i in range(N - 1):
		if i % 2 == 0:
			B1.append(A[i + 1] - A[i])
		else:
			B2.append(A[i] - A[i + 1])
	acc1 = [0] + list(accumulate(B1))
	acc2 = [0] + list(accumulate(B2))
	st1 = SparseTable(acc1, max)
	st2 = SparseTable(acc2, max)
	N1 = len(acc1)
	N2 = len(acc2)
	base = sum([a if i % 2 == 0 else 0 for (i, a) in enumerate(A)])
	ans = base
	for i in range(N1 - 1):
		l = acc1[i]
		r = st1.get(i + 1, N1)
		ans = max(ans, base + r - l)
	for i in range(N2 - 1):
		l = acc2[i]
		r = st2.get(i + 1, N2)
		ans = max(ans, base + r - l)
	print(ans)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	sum = 0
	for i in range(0, n, 2):
		sum += a[i]
	m = 0
	d = 0
	for i in range(1, n, 2):
		d += a[i] - a[i - 1]
		if d < 0:
			d = 0
		m = max(m, d)
	d = 0
	for i in range(2, n, 2):
		d += a[i - 1] - a[i]
		if d < 0:
			d = 0
		m = max(m, d)
	print(sum + m)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	e = s[::2]
	o = s[1::2]
	ans = cs = 0
	for i in range(len(o)):
		cs = max(0, cs + o[i] - e[i])
		ans = max(cs, ans)
	cs = 0
	for i in range(len(e) - 1):
		cs = max(0, cs + o[i] - e[i + 1])
		ans = max(cs, ans)
	print(sum(e) + ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	for i in range(len(l)):
		if i % 2 == 0:
			s = s + l[i]
	(o, e) = (0, 0)
	r = 0
	for i in range(1, n, 2):
		o = o + l[i]
		e = e + l[i - 1]
		if o > e:
			r = max(r, o - e)
		else:
			(o, e) = (0, 0)
	(o, e) = (0, 0)
	for i in range(2, n, 2):
		e = e + l[i]
		o = o + l[i - 1]
		if o > e:
			r = max(r, o - e)
		else:
			(e, o) = (0, 0)
	print(s + r)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	l = int(input())
	s = list(map(int, input().split()))
	total = 0
	for j in range(0, l, 2):
		total += s[j]
	best = 0
	max_best = 0
	for j in range(0, l, 2):
		if j + 1 == l:
			break
		best += s[j + 1] - s[j]
		max_best = max(best, max_best)
		if best < 0:
			best = 0
	best = 0
	for j in range(1, l, 2):
		if j + 1 == l:
			break
		best += s[j] - s[j + 1]
		max_best = max(best, max_best)
		if best < 0:
			best = 0
	print(total + max_best)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()

def ma(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far
for _ in range(t):
	(n,) = I()
	l = I()
	pre = [0] * n
	suf = [0] * n
	an = 0
	if n <= 2:
		print(max(l))
		continue
	d = []
	for i in range(n):
		if i > 0:
			d.append(l[i - 1] - l[i])
		if i % 2 == 0:
			pre[i] = pre[max(0, i - 2)] + l[i]
		if (n - i - 1) % 2:
			suf[n - i - 1] = suf[min(n - 1, n - i + 1)] + l[n - i - 1]
	x = [d[i] for i in range(n - 1) if i % 2]
	y = [-d[i] for i in range(n - 1) if i % 2 == 0]
	r = ma(x, len(x))
	p = ma(y, len(y))
	r = max(r, p)
	if r < 0:
		r = 0
	an = max(max(pre[n - 2], pre[n - 1]) + r, suf[1])
	for i in range(0, n - 3, 2):
		an = max(an, pre[i] + suf[i + 3])
	print(an)


from sys import stdin, stdout
from collections import Counter
from collections import defaultdict

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	n = ip()
	li = ai()
	cur = maxx = 0
	for i in range(0, n - 1, 2):
		cur += li[i + 1] - li[i]
		cur = max(0, cur)
		maxx = max(cur, maxx)
	cur = 0
	for i in range(1, n - 1, 2):
		cur += li[i] - li[i + 1]
		cur = max(0, cur)
		maxx = max(cur, maxx)
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += li[i]
	print(ans + maxx)


def max_sum(A):
	max_so_far = 0
	max_ending = 0
	for i in A:
		max_ending += i
		if max_ending < 0:
			max_ending = 0
		if max_ending > max_so_far:
			max_so_far = max_ending
	return max_so_far
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += arr[i]
	arr1 = []
	arr2 = []
	for i in range(n):
		if i % 2 == 0:
			if i - 1 >= 0:
				arr1.append(arr[i - 1] - arr[i])
			if i + 1 < n:
				arr2.append(arr[i + 1] - arr[i])
	print(ans + max(max_sum(arr1), max_sum(arr2)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	o = 0
	e = 0
	lp1 = 0
	rp1 = 1
	mlp = -1
	mrp = -1
	md = -1
	d = 0
	if n == 1:
		print(a[0])
		continue
	while rp1 < n:
		e += a[rp1 - 1]
		o += a[rp1]
		d = o - e
		if d < 0:
			lp1 = rp1 + 1
			o = 0
			e = 0
			d = 0
		if d > md:
			mlp = lp1
			mrp = rp1
			md = d
		rp1 += 2
	lp1 = 1
	rp1 = 2
	d = 0
	o = 0
	e = 0
	while rp1 < n:
		o += a[rp1 - 1]
		e += a[rp1]
		d = o - e
		if d < 0:
			lp1 = rp1 + 1
			o = 0
			e = 0
			d = 0
		if d > md:
			mlp = lp1
			mrp = rp1
			md = d
		rp1 += 2
	print(sum(a[::2]) + md)


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	d = 0
	mi = 0
	for j in range(0, n, 2):
		mi = mi + l[j]
	jj = mi
	p = 0
	mi = 0
	for j in range(0, n - 1, 2):
		if j + 1 < n:
			if l[j] <= l[j + 1]:
				p = p + l[j + 1] - l[j]
				if p > mi:
					mi = p
			else:
				p = p - l[j] + l[j + 1]
				if p < 0:
					p = 0
	p = 0
	for j in range(1, n, 2):
		if j + 1 < n:
			if l[j] > l[j + 1]:
				p = p - l[j + 1] + l[j]
				if p > mi:
					mi = p
				j = j + 1
			else:
				p = p + l[j] - l[j + 1]
				if p < 0:
					p = 0
				j = j + 1
	print(jj + mi)


import sys

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	n = int(input())
	arr = I()
	prefseven = [0] * (n + 1)
	prefsodd = [0] * (n + 1)
	for i in range(n):
		if i % 2:
			prefsodd[i] = prefsodd[i - 1] + arr[i]
			prefseven[i] = prefseven[i - 1]
		else:
			prefseven[i] = prefseven[i - 1] + arr[i]
			prefsodd[i] = prefsodd[i - 1]
	ans = 0
	currminodd = 0
	currmineven = 0
	for i in range(n):
		if i % 2:
			ans = max(prefsodd[i] - prefseven[i] - currminodd, ans)
			currminodd = min(prefsodd[i] - prefseven[i], currminodd)
		else:
			ans = max(prefsodd[i] - prefseven[i] - currmineven, ans)
			currmineven = min(prefsodd[i] - prefseven[i], currmineven)
	print(ans + sum(arr[::2]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	maxm = 0
	total = 0
	for i in range(0, n - 1, 2):
		total += a[i + 1] - a[i]
		if total < 0:
			total = 0
		maxm = max(maxm, total)
	total = 0
	for i in range(1, n - 1, 2):
		total += a[i] - a[i + 1]
		if total < 0:
			total = 0
		maxm = max(maxm, total)
	total = 0
	for i in range(0, n, 2):
		total += a[i]
	print(total + maxm)


rwe = int(input())
for qerw in range(rwe):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		continue
	d1 = []
	d2 = []
	sch = 0
	for i in range(0, n - 1, 2):
		d1.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		d2.append(-a[i + 1] + a[i])
	for i in range(0, n, 2):
		sch += a[i]
	ans = d1[0]
	s = 0
	for i in d1:
		s += i
		ans = max(ans, s)
		s = max(s, 0)
	s = 0
	for i in d2:
		s += i
		ans = max(ans, s)
		s = max(s, 0)
	print(sch + max(0, ans))


t = int(input())
import random
xx = random.randint
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if n % 2:
		l += [0] * 3
		n += 3
	else:
		l += [0] * 2
		n += 2
	odd = []
	even = [0]
	for i in range(n - 1, -1, -1):
		if i % 2:
			if odd:
				y = l[i] + max(even[-1], odd[-1][1])
				x = 0
				if len(odd) - 1:
					x = l[i] + max(odd[-1][0], even[-2])
				odd.append([x, y])
			else:
				odd.append([0, l[i]])
		else:
			even.append(even[-1] + l[i])
	odd.reverse()
	ans = odd[0][1]
	even = 0
	b = 0
	for i in range(n):
		if i % 2:
			b += 1
		else:
			even += l[i]
			if b + 1 < len(odd):
				ans = max(ans, even + odd[b + 1][1])
			ans = max(ans, even + odd[b][0])
	print(ans)


def solution(arr):
	even = 0
	for i in range(0, len(arr), 2):
		even = even + arr[i]
	diff = 0
	curr = 0
	for i in range(1, len(arr), 2):
		val = arr[i] - arr[i - 1]
		curr = curr + val
		diff = max(diff, curr)
		curr = max(curr, 0)
	curr = 0
	for j in range(1, len(arr), 2):
		if j + 1 == len(arr):
			break
		val = arr[j] - arr[j + 1]
		curr = curr + val
		diff = max(diff, curr)
		curr = max(curr, 0)
	return even + diff
for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(solution(arr))


def maxSubArraySum(a, size):
	max_so_far = -float('inf') - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	new = []
	for i in range(1, n, 2):
		new.append(arr[i] - arr[i - 1])
	sums = 0
	a = maxSubArraySum(new, len(new))
	new = []
	for i in range(1, n - 1, 2):
		new.append(arr[i] - arr[i + 1])
	b = maxSubArraySum(new, len(new))
	for i in range(0, n, 2):
		sums += arr[i]
	sums += max(a, b, 0)
	print(sums)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	arr = []
	res = 0
	for i in range(0, n, 2):
		res += l[i]
	for i in range(1, n, 2):
		arr.append(l[i] - l[i - 1])
	max_till_now = 0
	curr_max = 0
	for i in range(len(arr)):
		curr_max += arr[i]
		if curr_max < 0:
			curr_max = 0
		max_till_now = max(max_till_now, curr_max)
	ans = res + max_till_now
	arr = []
	for i in range(2, n, 2):
		arr.append(l[i - 1] - l[i])
	max_till_now = 0
	curr_max = 0
	for i in range(len(arr)):
		curr_max += arr[i]
		if curr_max < 0:
			curr_max = 0
		max_till_now = max(max_till_now, curr_max)
	ans = max(ans, res + max_till_now)
	print(ans)
	t -= 1


t = int(input())

def f(a):
	sums = [0]
	for i in range(len(a)):
		sums.append(a[i] + sums[-1])
	minn = [sums[0]]
	for i in range(1, len(sums)):
		minn.append(min(minn[-1], sums[i]))
	maxx = [sums[-1]]
	for i in range(1, len(sums)):
		maxx.append(max(maxx[-1], sums[len(sums) - i - 1]))
	maxx.reverse()
	diff = [0]
	for i in range(1, len(sums)):
		diff.append(maxx[i] - minn[i])
	return max(diff)
for tt in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	ch = []
	for i in range(1, n):
		if i % 2 == 1:
			ch.append(a[i] - a[i - 1])
		else:
			ch.append(a[i - 1] - a[i])
	l = []
	r = []
	for i in range(len(ch)):
		if i % 2 == 0:
			l.append(ch[i])
		else:
			r.append(ch[i])
	sum_org = 0
	for i in range(n):
		if i % 2 == 0:
			sum_org += a[i]
	summ = sum_org + max(f(l), f(r), 0)
	print(summ)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	summ = 0
	ch0 = 0
	ch1 = 0
	for i in range(len(a)):
		if i % 2 == 0:
			ch0 += a[i]
	v1 = [0 for i in range(n // 2)]
	v2 = [0 for i in range((n - 1) // 2)]
	for i in range(n // 2):
		v1[i] = a[2 * i + 1] - a[2 * i]
	for i in range(0, (n - 1) // 2):
		v2[i] = a[2 * i + 1] - a[2 * i + 2]
	csum = 0
	msum = 0
	ans1 = ch0
	for i in v1:
		csum += i
		msum = min(csum, msum)
		ans1 = max(csum - msum + ch0, ans1)
	csum = 0
	msum = 0
	ans2 = ch0
	for i in v2:
		csum += i
		msum = min(csum, msum)
		ans2 = max(csum - msum + ch0, ans2)
	print(max(ans1, ans2))


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	x = ip()
	maxdf = 0
	diff = 0
	i = 0
	while i + 1 < n:
		diff += x[i + 1] - x[i]
		if diff < 0:
			diff = 0
		else:
			maxdf = max(maxdf, diff)
		i += 2
	diff = 0
	for i in range(1, n - 1, 2):
		diff += x[i] - x[i + 1]
		if diff < 0:
			diff = 0
		else:
			maxdf = max(maxdf, diff)
	sm = sum([x[i] for i in range(n) if i % 2 == 0])
	print(sm + maxdf)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(v) for v in input().split()]
	v1 = []
	v2 = []
	m = 0
	s = sum(a[::2])
	for j in range(0, n - n % 2, 2):
		v1.append(a[j + 1] - a[j])
	for j in range(1, n - (1 - n % 2), 2):
		v2.append(a[j] - a[j + 1])
	dp = [0]
	for j in range(len(v1)):
		dp.append(max(v1[j] + dp[-1], v1[j]))
	m = max(dp)
	dp = [0]
	for j in range(len(v2)):
		dp.append(max(v2[j] + dp[-1], v2[j]))
	m = max(max(dp), m, 0)
	print(s + m)


for w in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(0, n, 2):
		ans += a[i]
	l = []
	for i in range(1, n, 2):
		l.append(a[i] - a[i - 1])
	temp = 0
	kadane = -1
	for i in range(len(l)):
		temp += l[i]
		if temp < 0:
			temp = 0
		kadane = max(kadane, temp)
	kadane_endgame = kadane
	kadane = -1
	temp = 0
	l = []
	for i in range(1, n, 2):
		if i + 1 < n:
			l.append(a[i] - a[i + 1])
	for i in range(len(l)):
		temp += l[i]
		if temp < 0:
			temp = 0
		kadane = max(kadane, temp)
	kadane_endgame = max(kadane, kadane_endgame)
	ans = max(ans, ans + kadane_endgame)
	print(ans)


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	for _ in range(int(input())):
		(n,) = aj()
		A = aj()
		m1 = 0
		cur = 0
		for i in range(0, n - 1, 2):
			cur += A[i + 1] - A[i]
			if cur < 0:
				cur = 0
			m1 = max(m1, cur)
		cur = 0
		for i in range(1, n - 1, 2):
			cur += A[i] - A[i + 1]
			if cur < 0:
				cur = 0
			m1 = max(m1, cur)
		ans = 0
		for i in range(0, n, 2):
			ans += A[i]
		print(ans + m1)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import sys
input = sys.stdin.readline

def maxSubArraySum(a, size):
	if size == 0:
		return 0
	max_so_far = -10 ** 18
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		continue
	s = 0
	g = []
	g2 = []
	for i in range(0, n - 1, 2):
		s += a[i]
		g.append(a[i + 1] - a[i])
	if n % 2:
		s += a[-1]
	for i in range(2, n, 2):
		g2.append(a[i - 1] - a[i])
	print(s + max(maxSubArraySum(g, len(g)), maxSubArraySum(g2, len(g2)), 0))


for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(a) == 1:
		print(a[0])
		continue
	elif len(a) == 2:
		print(max(a))
		continue
	zero = [a[i + 1] - a[i] for i in range(0, n - n % 2, 2)]
	one = [a[i] - a[i + 1] for i in range(1, n - (1 - n % 2), 2)]
	ans_zero = zero[0]
	summ = 0
	for i in zero:
		summ += i
		ans_zero = max(ans_zero, summ)
		summ = max(0, summ)
	ans_one = one[0]
	summ = 0
	for i in one:
		summ += i
		ans_one = max(ans_one, summ)
		summ = max(0, summ)
	summ = sum(a[::2])
	ans = summ + max(ans_one, ans_zero)
	print(max(summ, ans))


from __future__ import division, print_function
import os
import sys, math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def max_sub_array(v):
	size = len(v)
	(max_so_far, max_ending_here) = (-math.inf, 0)
	for i in range(size):
		max_ending_here += v[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def main():
	Test = int(input())
	while Test:
		Test -= 1
		(ans, n) = (0, int(input()))
		v = list(map(int, input().split()))
		(a, b) = ([], [])
		for i in range(n):
			if not i & 1:
				ans += v[i]
			if i == 0:
				continue
			if i & 1:
				a.append(v[i] - v[i - 1])
			else:
				b.append(v[i - 1] - v[i])
		print(ans + max(0, max_sub_array(a), max_sub_array(b)))
	return None
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def kadane_sum(lista):
	max_local_np = max_local_p = max_local_np2 = max_local_p2 = 0
	(best, best2) = (0, 0)
	for y in range(1, len(lista), 2):
		max_local_p += lista[y - 1]
		max_local_np += lista[y]
		best = max(best, max_local_np - max_local_p)
		if max_local_p > max_local_np:
			best = max(best, max_local_np - max_local_p)
			max_local_np = 0
			max_local_p = 0
		best = max(best, max_local_np - max_local_p)
	for y in range(2, len(lista), 2):
		max_local_p2 += lista[y]
		max_local_np2 += lista[y - 1]
		best2 = max(best2, max_local_np2 - max_local_p2)
		if max_local_p2 > max_local_np2:
			best2 = max(best2, max_local_np2 - max_local_p2)
			max_local_np2 = 0
			max_local_p2 = 0
		best2 = max(best2, max_local_np2 - max_local_p2)
	best = max(best, best2)
	return best
for _ in range(int(input())):
	ilosc = input()
	lista = [int(x) for x in input().split()]
	best = kadane_sum(lista)
	print(sum(lista[::2]) + best)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = [0]
	odd = [0]
	mino = 0
	mine = 0
	super = 0
	i = 1
	summer = a[0]
	while i < n:
		if i % 2 == 0:
			summer += a[i]
			olde = even[-1]
			super = max(super, -(a[i] - a[i - 1]) - mine + olde)
			mine = min(mine, -(a[i] - a[i - 1]) + olde)
			even.append(-(a[i] - a[i - 1]) + olde)
		else:
			oldo = odd[-1]
			super = max(super, a[i] - a[i - 1] + oldo - mino)
			mino = min(mino, a[i] - a[i - 1] + oldo)
			odd.append(a[i] - a[i - 1] + oldo)
		i += 1
	print(summer + super)


def kadane(lis):
	if len(lis) == 0:
		return 0
	max_curr = lis[0]
	max_global = lis[0]
	for i in range(1, len(lis)):
		max_curr = max(max_curr + lis[i], lis[i])
		max_global = max(max_global, max_curr)
	return max_global
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	even = []
	odd = []
	while i < n - 1:
		even.append(l[i + 1] - l[i])
		i += 2
	i = 1
	while i < n - 1:
		odd.append(l[i] - l[i + 1])
		i += 2
	a = kadane(even)
	b = kadane(odd)
	sum_even = 0
	for i in range(n):
		if i % 2 == 0:
			sum_even += l[i]
	print(sum_even + max(0, a, b))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mn_e = 10 ** 9
	mn_o = 0
	curr = 0
	mx = 0
	total = 0
	for i in range(n):
		num = arr[i]
		if i % 2 == 0:
			total += num
			num = -num
		curr += num
		if i % 2:
			mx = max(mx, curr - mn_o)
			mn_o = min(mn_o, curr)
		else:
			mx = max(mx, curr - mn_e)
			mn_e = min(mn_e, curr)
	print(total + mx)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split(' ')))
	prefixArr = [0]
	out = 0
	for i in range(1, n):
		if i % 2 != 0:
			diff = a[i] - a[i - 1]
		else:
			diff = a[i - 1] - a[i]
		if diff > diff + prefixArr[max(0, i - 2)]:
			prefixArr.append(diff)
		else:
			prefixArr.append(diff + prefixArr[max(0, i - 2)])
	for i in range(n):
		if i % 2 == 0:
			out += a[i]
	print(out + max(prefixArr))


import math
from collections import deque
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	for j in range(0, n):
		if j % 2 == 0:
			s += l[j]
	l1 = []
	for j in range(0, n - 1, 2):
		l1.append(l[j + 1] - l[j])
	l2 = []
	for j in range(1, n - 1, 2):
		l2.append(l[j] - l[j + 1])
	print(max(s, s + maxSubArraySum(l1, len(l1)), s + maxSubArraySum(l2, len(l2))))
t = int(input())
for i in range(0, t):
	main()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(0, n, 2):
		ans += a[i]
	mx = ans
	cnt = 0
	for i in range(1, n, 2):
		cnt += a[i] - a[i - 1]
		mx = max(mx, ans + cnt)
		if cnt < 0:
			cnt = 0
	cnt = 0
	for i in range(2, n, 2):
		cnt += a[i - 1] - a[i]
		mx = max(mx, ans + cnt)
		if cnt < 0:
			cnt = 0
	print(mx)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	Sum = sum(arr[::2])
	(ms, cs) = (0, 0)
	for i in range(0, n - n % 2, 2):
		cs = max(0, cs + arr[i + 1] - arr[i])
		ms = max(cs, ms)
	cs = 0
	for i in range(1, n - int(n % 2 == 0), 2):
		cs = max(0, cs + arr[i] - arr[i + 1])
		ms = max(cs, ms)
	print(ms + Sum)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum([a[i] for i in range(n) if i % 2 == 0])
	dp = [0] * n
	for i in range(2, n, 2):
		dp[i] = max(dp[i - 2] + a[i - 1] - a[i], a[i - 1] - a[i])
	for i in range(1, n, 2):
		if i >= 2:
			dp[i] = max(dp[i - 2] + a[i] - a[i - 1], a[i] - a[i - 1])
		else:
			dp[i] = a[i] - a[i - 1]
	print(s + max(max(dp), 0))


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')

def cal(s):
	res = 0
	for init in range(1000):
		cur = init
		ok = True
		for i in range(len(s)):
			res = res + 1
			if s[i] == '+':
				cur = cur + 1
			else:
				cur = cur - 1
			if cur < 0:
				ok = False
				break
		if ok:
			break
	print(res)
t = fi()

def sd(a):
	c = 0
	for i in range(0, n, 2):
		c += a[i]
	return c

def ka(a):
	maxi = 0
	c = 0
	for i in range(len(a)):
		if c + a[i] > a[i]:
			c += a[i]
		else:
			c = a[i]
		maxi = max(maxi, c)
	return maxi
while t > 0:
	t -= 1
	n = fi()
	a = li()
	maxi = sd(a)
	d = []
	e = []
	for i in range(0, n, 2):
		if len(d):
			d.append(d[-1] + a[i])
		else:
			d.append(a[i])
	for i in range(1, n, 2):
		if len(e):
			e.append(e[-1] + a[i])
		else:
			e.append(a[i])
	l1 = []
	l2 = []
	for i in range(1, n, 2):
		l1.append(a[i] - a[i - 1])
	for i in range(2, n, 2):
		l2.append(-a[i] + a[i - 1])
	print(sd(a) + max(ka(l1), ka(l2)))


import os
import sys
input = sys.stdin.buffer.readline
from math import *
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(sum(arr))
	else:
		brr = []
		crr = []
		s = 0
		i = 0
		while i < n:
			s += arr[i]
			i += 2
		i = 0
		while i < n:
			if i + 1 < n:
				brr.append(arr[i + 1] - arr[i])
			if i > 0:
				crr.append(arr[i - 1] - arr[i])
			i += 2
		maxbrr = 0
		maxcrr = 0
		c = 0
		for x in brr:
			c += x
			if c < 0:
				c = 0
			maxbrr = max(maxbrr, c)
		c = 0
		for x in crr:
			c += x
			if c < 0:
				c = 0
			maxcrr = max(maxcrr, c)
		print(s + max(maxbrr, maxcrr))


def solve(n, a):
	n2 = n // 2
	x = [None] * n2
	x2 = [None] * n2
	a.append(a[-1])
	init = 0 if n % 2 == 0 else a[-1]
	for i in range(n2):
		init += a[i * 2]
		x[i] = a[2 * i + 1] - a[2 * i]
		x2[i] = a[2 * i + 1] - a[2 * i + 2]
	return init + max(gs(x), gs(x2), 0)

def gs(a):
	cur = 0
	mm = 0
	best = 0
	for v in a:
		cur += v
		if best < cur - mm:
			best = cur - mm
		if cur < mm:
			mm = cur
	return best
t = int(input())
for i_t in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	print(solve(n, a))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	sm = 0
	for (i, x) in enumerate(arr):
		if not i % 2:
			sm += x
	dp1 = [0]
	dp2 = [0]
	for i in range(n - 1):
		if i % 2:
			dp2.append(arr[i] - arr[i + 1])
		else:
			dp1.append(arr[i + 1] - arr[i])
	for i in range(1, len(dp1)):
		dp1[i] = max(dp1[i] + dp1[i - 1], 0)
	for i in range(1, len(dp2)):
		dp2[i] = max(dp2[i] + dp2[i - 1], 0)
	print(sm + max(max(dp1), max(dp2)))


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	m = 0
	d = 0
	p = A[0::2]
	tot = sum(p)
	for i in range(1, n, 2):
		d += A[i] - A[i - 1]
		if d < 0:
			d = 0
		m = max(m, d)
	d = 0
	for i in range(2, n, 2):
		d += A[i - 1] - A[i]
		if d < 0:
			d = 0
		m = max(m, d)
	print(tot + m)


debug = False
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [[0] * 3 for i in range(n + 1)]
	for i in range(n):
		dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + (0 if i & 1 else arr[i]))
		if i + 2 <= n:
			dp[i + 2][1] = max(dp[i + 2][1], max(dp[i][0], dp[i][1]) + (arr[i] if i & 1 else arr[i + 1]))
		dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][0], dp[i][1], dp[i][2]) + (0 if i & 1 else arr[i]))
	print(max(dp[n]))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	f = []
	s = []
	num = 0
	if n < 3:
		print(max(arr))
		continue
	for i in range(n):
		if not i & 1:
			num += arr[i]
	for i in range(n - 1):
		if not i & 1:
			f.append(arr[i + 1] - arr[i])
		else:
			s.append(arr[i] - arr[i + 1])
	ans = f[0]
	sum = 0
	min_sum = 0
	for i in range(len(f)):
		sum += f[i]
		ans = max(ans, sum - min_sum)
		min_sum = min(min_sum, sum)
	ans2 = s[0]
	sum = 0
	min_sum = 0
	for i in range(len(s)):
		sum += s[i]
		ans2 = max(ans2, sum - min_sum)
		min_sum = min(min_sum, sum)
	num += max(ans, ans2) if max(ans, ans2) > 0 else 0
	print(num)


import math
t = int(input())
for hello in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [0] * (n // 2 + 1)
	dp1 = [0] * (n // 2 + 1)
	summ1 = 0
	for i in range(n // 2):
		dp[i + 1] = a[2 * i + 1] - a[2 * i]
	for i in range((n - 1) // 2):
		dp1[i + 1] = a[2 * i + 1] - a[2 * i + 2]
	for i in range(n):
		if i % 2 == 0:
			summ1 += a[i]
	summ = 0
	maxSum = 0
	for i in range(len(dp)):
		summ += dp[i]
		if summ > maxSum:
			maxSum = summ
		if summ < 0:
			summ = 0
	summ = 0
	maxSum1 = 0
	for i in range(len(dp1)):
		summ += dp1[i]
		if summ > maxSum1:
			maxSum1 = summ
		if summ < 0:
			summ = 0
	print(summ1 + max(maxSum, maxSum1))


import sys
input = sys.stdin.readline

def testcase():
	N = int(input())
	A = [int(x) for x in input().strip().split()]
	even = [a for (i, a) in enumerate(A) if i % 2 == 0]
	odd = [a for (i, a) in enumerate(A) if i % 2]
	ans = sum(even)
	diff1 = [0] * (N // 2)
	diff2 = [0] * (N // 2)
	if N % 2:
		for (i, o) in enumerate(odd):
			diff1[i] = o - even[i]
			diff2[i] = o - even[i + 1]
	else:
		for (i, o) in enumerate(odd[:-1]):
			diff1[i] = o - even[i]
			diff2[i] = o - even[i + 1]
		diff1[-1] = odd[-1] - even[-1]
	cumsum = 0
	maxi = 0
	for (i, d) in enumerate(diff1):
		cumsum += d
		if cumsum > 0:
			maxi = max(maxi, cumsum)
			continue
		cumsum = 0
	cumsum = 0
	for (i, d) in enumerate(diff2):
		cumsum += d
		if cumsum > 0:
			maxi = max(maxi, cumsum)
			continue
		cumsum = 0
	print(ans + maxi)

def main():
	t = int(input())
	for _ in range(t):
		testcase()
main()


import math
from math import log2, sqrt
from bisect import bisect_left, bisect_right
import bisect
import sys
from sys import stdin, stdout
import os
sys.setrecursionlimit(pow(10, 6))
import collections
from collections import defaultdict
from statistics import median
inf = float('inf')

def fun():
	maxa = 0
	count = 0
	index = 0
	while index + 1 < len(l):
		count = max(0, count - l[index] + l[index + 1])
		maxa = max(maxa, count)
		index += 2
	index = 2
	count = 0
	while index < len(l):
		count = max(0, count - l[index] + l[index - 1])
		maxa = max(maxa, count)
		index += 2
	return maxa
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = fun()
	suma = sum(l[::2])
	print(suma + ans)


def f(L):
	n = len(L)
	if n == 1:
		return L[0]
	if n == 2:
		return max(L[0], L[1])
	S = []
	P = []
	bs = 0
	for i in range(0, n, 2):
		bs += L[i]
	s = 0
	for i in range(1, n, 2):
		s += L[i] - L[i - 1]
		S.append(s)
	m = 0
	for i in range(2, n, 2):
		m += L[i - 1] - L[i]
		P.append(m)
	maxm1 = [S[0]]
	maxm2 = [P[0]]
	k = len(S)
	m = len(P)
	for i in range(1, k):
		maxm1.append(max(S[i] - S[i - 1], S[i] - S[i - 1] + maxm1[-1]))
	for i in range(1, m):
		maxm2.append(max(P[i] - P[i - 1], P[i] - P[i - 1] + maxm2[-1]))
	c = max(max(maxm1), max(maxm2))
	if c >= 0:
		return bs + c
	return bs
n = int(input())
for i in range(n):
	x = input()
	L = list(map(int, input().split()))
	print(f(L))


for x in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	odd = 0
	even = 0
	for x1 in range(n):
		if x1 % 2:
			odd += l[x1]
		else:
			even += l[x1]
	ans = max(odd, even)
	s2 = 0
	s3 = 0
	for x1 in range(0, n - 1, 2):
		a = l[x1 + 1] - l[x1]
		s2 += a
		if s2 < 0:
			s2 = 0
		s3 = max(s2, s3, 0)
		ans = max(even + s3, ans)
	s2 = 0
	s3 = 0
	for x1 in range(1, n - 1, 2):
		a = l[x1] - l[x1 + 1]
		s2 += a
		if s2 < 0:
			s2 = 0
		s3 = max(s2, s3)
		ans = max(even + s3, ans)
	print(ans)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())

def maxSubArraySum(a, size, start):
	maxint = 10 ** 9 + 1
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(start, size, 2):
		if i + 1 >= size or i >= size:
			break
		if start == 0:
			max_ending_here = max_ending_here + a[i + 1] - a[i]
		else:
			max_ending_here = max_ending_here + a[i] - a[i + 1]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
while t:
	t -= 1
	n = int(fastinput())
	b = list(map(int, fastinput().split()))
	ans = max(0, maxSubArraySum(b, n, 0), maxSubArraySum(b, n, 1))
	s = 0
	for i in range(0, n, 2):
		s += b[i]
	print(ans + s)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def maxSubArraySum(a, size):
	max_so_far = -float('inf')
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def gift():
	for _ in range(t):
		n = int(input())
		arry = list(map(int, input().split()))
		sum1 = 0
		for i in range(n // 2 + n % 2):
			sum1 += arry[2 * i]
		arra = []
		arrb = []
		for i in range(n // 2):
			arra.append(arry[2 * i + 1] - arry[2 * i])
		for i in range(n // 2 - 1 + n % 2):
			arrb.append(arry[2 * i + 1] - arry[2 * (i + 1)])
		diua = maxSubArraySum(arra, len(arra))
		diub = maxSubArraySum(arrb, len(arrb))
		yield (sum1 + max(diua, diub, 0))
t = int(input())
ans = gift()
print(*ans, sep='\n')


import sys
from collections import deque
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, a) = (int(input()), list(map(int, input().split())))
	mx = 0
	for start in range(2):
		sm = 0
		for i in range(start, n, 2):
			if i + 1 >= n:
				continue
			cc = a[i + 1] - a[i] if start == 0 else a[i] - a[i + 1]
			sm += cc
			if sm < 0:
				sm = 0
			mx = max(mx, sm)
	for i in range(0, n, 2):
		mx += a[i]
	print(mx)


import sys
readline = sys.stdin.readline

def solve():
	N = int(readline())
	A = list(map(int, readline().split()))

	def _sub(d):
		gain0 = [0] * (N // 2)
		j = 0
		for i in range(0, N, 2):
			if not 0 <= i + d < N:
				continue
			gain0[j] = A[i + d] - A[i]
			j += 1
		for i in range(len(gain0)):
			gain0[i] = gain0[0] if i == 0 else gain0[i] + gain0[i - 1]
		m = 0
		gain = 0
		for v in gain0:
			gain = max(gain, v - m)
			m = min(m, v)
		return gain
	a = sum(A[0:N:2])
	a0 = _sub(-1) + a
	a1 = _sub(1) + a
	print(max(a0, a1))
T = int(readline())
for i in range(T):
	solve()


import sys

def kadane(b, ch):
	mx = b[0]
	cur = 0
	ms = 0
	me = 0
	start = 0
	if ch == 1:
		ms += 1
		me += 1
	for h in range(len(b)):
		if cur + b[h] >= 0:
			if cur < 0:
				cur = b[h]
				start = h
			else:
				cur += b[h]
		else:
			if cur > mx:
				mx = cur
				ms = 2 * start
				me = 2 * h
				if ch == 1:
					ms += 1
					me += 1
			cur = b[h]
			start = h
		if cur > mx:
			mx = cur
			ms = 2 * start
			me = 2 * h
			if ch == 1:
				ms += 1
				me += 1
	if cur > mx:
		mx = cur
		ms = 2 * start
		me = 2 * (len(b) - 1)
		if ch == 1:
			ms += 1
			me += 1
	return (mx, ms, me)

def reverse(arr, i, j):
	for p in range(i, j + 1, 2):
		(arr[p], arr[p + 1]) = (arr[p + 1], arr[p])
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	n = int(sys.stdin.readline())
	a = [int(x) for x in sys.stdin.readline().split()]
	if n == 1:
		ans_arr.append(str(a[0]))
	elif n == 2:
		ans_arr.append(str(max(a[0], a[1])))
	else:
		ans = 0
		for e in range(n):
			if e % 2 == 0:
				ans += a[e]
		b1 = []
		b2 = []
		for g in range(0, n, 2):
			if g + 1 < n:
				b1.append(a[g + 1] - a[g])
		for h in range(1, n, 2):
			if h + 1 < n:
				b2.append(a[h] - a[h + 1])
		(mx1, ms1, me1) = kadane(b1, 0)
		(mx2, ms2, me2) = kadane(b2, 1)
		ans1 = 0
		ans2 = 0
		if mx1 > mx2:
			ms = ms1
			me = me1
			reverse(a, ms, me)
			for p in range(len(a)):
				if p % 2 == 0:
					ans1 += a[p]
		else:
			ms = ms2
			me = me2
			reverse(a, ms, me)
			for p in range(len(a)):
				if p % 2 == 0:
					ans2 += a[p]
		ans = max(ans, ans1)
		ans = max(ans, ans2)
		ans_arr.append(str(ans))
print('\n'.join(ans_arr))


t = int(input())
buf = []
for _ in range(t):
	n = int(input())
	aaa = list(map(int, input().split()))
	dp = [0, 0, 0, 0]
	for (i, a) in enumerate(aaa):
		if i % 2 == 0:
			dp[3] = max(dp[1], dp[3]) + a
			dp[1] = max(dp[0], dp[1])
			dp[0] += a
		else:
			dp[3] = max(dp[2], dp[3])
			dp[2] = max(dp[0], dp[2]) + a
			dp[1] += a
	if n % 2 == 0:
		dp[2] = 0
	else:
		dp[1] = 0
	buf.append(max(dp))
print('\n'.join(map(str, buf)))


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())

def find_max(diff):
	max_sum = 0
	sum_ = 0
	for i in range(len(diff)):
		sum_ += diff[i]
		if sum_ < 0:
			sum_ = 0
		else:
			max_sum = max(max_sum, sum_)
	return max_sum
t = oint()
for _ in range(t):
	n = oint()
	a = list(rint())
	diff_even = []
	for i in range(0, n - 1, 2):
		diff_even.append(a[i + 1] - a[i])
	diff_odd = []
	for i in range(1, n - 1, 2):
		diff_odd.append(a[i] - a[i + 1])
	ans = sum(a[::2]) + max(find_max(diff_even), find_max(diff_odd))
	print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	best = [0, 0, 0]
	st = 0
	end = 0
	res = 0
	for i in range(n // 2):
		res += -a[i * 2] + a[i * 2 + 1]
		if res < 0:
			st = -1
			end = -1
			res = 0
		else:
			if st != -1:
				end = i * 2 + 1
			else:
				st = i * 2
				end = i * 2 + 1
			if res > best[0]:
				best[0] = res
				best[1] = st
				best[2] = end
	res = 0
	end = 0
	st = 0
	for i in range(n // 2 - 1 + n % 2):
		res += a[i * 2 + 1] - a[i * 2 + 2]
		if res < 0:
			st = -1
			end = -1
			res = 0
		else:
			if st != -1:
				end = i * 2 + 1
			else:
				st = i * 2
				end = i * 2 + 1
			if res > best[0]:
				best[0] = res
				best[1] = st
				best[2] = end
	sm = 0
	for i in range(0, n, 2):
		sm += a[i]
	print(sm + best[0])
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(tongchan, tongle) = (0, 0)
	ans = 0
	(maxchan, maxle) = (0, 0)
	(minchan, minle) = (0, 0)
	for i in range(len(a)):
		if i % 2 == 0:
			tongchan += a[i]
			minchan = min(minchan, tongle - tongchan)
			maxchan = max(maxchan, tongle - tongchan - minchan)
		else:
			tongle += a[i]
			minle = min(minle, tongle - tongchan)
			maxle = max(maxle, tongle - tongchan - minle)
	print(tongchan + max(maxchan, maxle))


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
dgnl = lambda x: sqrt(2 * x ** 2)
for _ in range(I()):
	n = I()
	a = L()
	if n & 1:
		a += (0,)
	ans = 0
	cur = 0
	prf = 0
	for i in range(0, n, 2):
		prf += a[i + 1] - a[i]
		if i:
			cur += a[i - 1] - a[i]
		if prf < 0:
			prf = 0
		if cur < 0:
			cur = 0
		ans = max(ans, prf, cur)
	print(sum([a[i] for i in range(0, n, 2)]) + ans)


def maxeve(arr):
	sm = sum(arr[::2])
	(ms, cs) = (0, 0)
	for i in range(0, len(arr) - 1, 2):
		cs = max(cs + arr[i + 1] - arr[i], 0)
		ms = max(cs, ms)
	cs = 0
	for i in range(1, len(arr) - 1, 2):
		cs = max(0, cs + arr[i] - arr[i + 1])
		ms = max(cs, ms)
	return ms + sm
for i in range(int(input())):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(maxeve(lst))


def kadane(arr):
	(mx, cur) = (0, 0)
	for i in arr:
		cur += i
		if mx < cur:
			mx = cur
		if cur < 0:
			cur = 0
	return mx
for i in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	even = 0
	for j in range(0, n, 2):
		even += arr[j]
	(diff1, diff2) = ([], [])
	for k in range(1, n, 2):
		diff1.append(arr[k] - arr[k - 1])
		if k + 1 < n:
			diff2.append(arr[k] - arr[k + 1])
	ans = even + max(0, kadane(diff1), kadane(diff2))
	print(ans)


def bhbhhbh(a, size):
	bhbhbhbhbh = 0
	fnekfke = -10000000000
	for i in range(0, size):
		bhbhbhbhbh = bhbhbhbhbh + a[i]
		if fnekfke < bhbhbhbhbh:
			fnekfke = bhbhbhbhbh
		if bhbhbhbhbh < 0:
			bhbhbhbhbh = 0
	return fnekfke
fgf = True
t = int(input())
for xxx in range(t):
	n = int(input())
	li = [int(x) for x in input().split()]
	leftelememe = []
	lerighttt = []
	for i in range(1, len(li), 2):
		leftelememe.append(li[i] - li[i - 1])
		if i + 1 < len(li) and fgf:
			lerighttt.append(li[i] - li[i + 1])
	newjfnewjfn = 0
	for i in range(0, len(li), 2):
		newjfnewjfn = newjfnewjfn + li[i]
	maxans = max(bhbhhbh(lerighttt, len(lerighttt)), bhbhhbh(leftelememe, len(leftelememe)))
	if maxans > 0 and fgf:
		print(newjfnewjfn + maxans)
	else:
		print(newjfnewjfn)


def max_subarray(numbers):
	best_sum = 0
	current_sum = 0
	for x in numbers:
		current_sum = max(0, current_sum + x)
		best_sum = max(best_sum, current_sum)
	return best_sum
t = int(input())
for _ in range(t):
	l = int(input())
	a = list(map(int, input().split()))
	z = []
	y = []
	evensum = 0
	for i in range(l // 2):
		z.append(a[i * 2 + 1] - a[i * 2])
		if i * 2 + 2 < l:
			y.append(a[i * 2 + 1] - a[i * 2 + 2])
		evensum += a[i * 2]
	if l % 2 == 1:
		evensum += a[-1]
	print(evensum + max(max_subarray(z), max_subarray(y)))


def kadane(lis):
	max_so_far = 0
	size = len(lis)
	max_curr = 0
	for i in range(0, size):
		max_curr = max(lis[i], lis[i] + max_curr)
		if max_so_far < max_curr:
			max_so_far = max_curr
	return max_so_far
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = sum(l[0:n:2])
	(even, odd) = ([], [])
	for i in range(n - 1):
		if i % 2:
			odd.append(l[i] - l[i + 1])
		else:
			even.append(l[i + 1] - l[i])
	xtra = max(kadane(even), kadane(odd), 0)
	print(s + xtra)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	Sum = sum(arr[::2])
	(mx, cur) = (0, 0)
	for i in range(0, n - (n & 1), 2):
		cur = max(0, cur + arr[i + 1] - arr[i])
		mx = max(mx, cur)
	cur = 0
	for i in range(1, n - int(n % 2 == 0), 2):
		cur = max(0, cur + arr[i] - arr[i + 1])
		mx = max(mx, cur)
	print(mx + Sum)


def kadane(A):
	ans = float('-inf')
	cur = 0
	for a in A:
		cur = max(cur + a, a)
		ans = max(ans, cur)
	return ans

def solve(A, n):
	S = sum(A[::2])
	B1 = []
	B2 = []
	for i in range(0, n - 1, 2):
		B1.append(A[i + 1] - A[i])
	for i in range(1, n - 1, 2):
		B2.append(-A[i + 1] + A[i])
	a = kadane(B1)
	b = kadane(B2)
	return max(S + a, S + b, S)
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	print(solve(A, n))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	odd = 0
	even = 0
	i = 0
	j = 0
	maxDif = 0
	while j < n - 1:
		even += arr[j]
		odd += arr[j + 1]
		if even > odd:
			even = 0
			odd = 0
			i = j
		maxDif = max(maxDif, odd - even)
		j += 2
	odd = 0
	even = 0
	i = 1
	j = 1
	while j < n - 1:
		odd += arr[j]
		even += arr[j + 1]
		if even > odd:
			even = 0
			odd = 0
			i = j
		maxDif = max(maxDif, odd - even)
		j += 2
	print(sum([arr[i] for i in range(n) if i % 2 == 0]) + maxDif)


def f(al):
	ar1 = []
	ar2 = []
	i = 0
	while i < len(al) - 1:
		ar1.append(al[i + 1] - al[i])
		i = i + 2
	i = 0
	while i < len(al) - 2:
		ar2.append(al[i + 1] - al[i + 2])
		i = i + 2
	return (ar1, ar2)

def subarraymax(nums):
	if len(nums) == 0:
		return 0
	sum = res = nums[0]
	for i in range(1, len(nums)):
		sum = max(nums[i], sum + nums[i])
		res = max(res, sum)
	return res
for tc in range(int(input())):
	_ = input()
	al = list(map(int, input().split()))
	ini = 0
	for i in range(0, len(al), 2):
		ini = ini + al[i]
	(s1, s2) = f(al)
	delta = max(subarraymax(s1), subarraymax(s2))
	if delta <= 0:
		print(ini)
	else:
		print(ini + delta)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	even = 0
	for i in range(0, n, 2):
		even += arr[i]
	ans = even
	left = []
	for i in range(1, n, 2):
		left.append(arr[i] - arr[i - 1])
	if len(left) != 0:
		s = left[0]
		dp = [0 for i in range(n + 1)]
		dp[0] = left[0]
		for i in range(1, len(left)):
			dp[i] = max(dp[i - 1] + left[i], left[i])
		temp = max(dp)
		ans = max(ans, even + temp)
	right = []
	for i in range(1, n - 1, 2):
		right.append(arr[i] - arr[i + 1])
	if len(right) != 0:
		s = right[0]
		dp = [0 for i in range(n + 1)]
		dp[0] = right[0]
		for i in range(1, len(right)):
			dp[i] = max(dp[i - 1] + right[i], right[i])
		temp = max(dp)
		ans = max(ans, even + temp)
	print(ans)


t = int(input())

def kadane(r):
	(sum_here, sum_max) = (0, 0)
	for i in r:
		sum_here = max(i, i + sum_here)
		sum_max = max(sum_max, sum_here)
	return sum_max
for _ in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	if n % 2:
		l.append(0)
	sum = 0
	(p, q) = ([], [])
	for i in range(0, n, 2):
		sum += l[i]
		p.append(l[i + 1] - l[i])
	for i in range(1, n - 1, 2):
		q.append(l[i] - l[i + 1])
	print(max(kadane(p), kadane(q)) + sum)


def kadane(l):
	length = len(l)
	maxsub = globalmax = l[0]
	for i in range(1, length):
		maxsub = max(l[i], maxsub + l[i])
		globalmax = max(globalmax, maxsub)
	return globalmax
t = int(input(''))
while t > 0:
	n = int(input(''))
	a = list(map(int, input().split()))
	neighbours = []
	oddsum = evensum = 0
	l1 = [0]
	l2 = [0]
	if n == 1:
		ans = a[0]
	else:
		for i in range(0, len(a), 2):
			if i != len(a) - 1:
				l1.append(a[i + 1] - a[i])
			evensum += a[i]
		ans = evensum
		for j in range(1, len(a), 2):
			if j != len(a) - 1:
				l2.append(a[j] - a[j + 1])
		change = max(kadane(l1), kadane(l2))
		if change > 0:
			ans += change
	print(ans)
	t -= 1


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().strip('\n').split()))
res = []
for _ in range(int(input())):
	n = int(input())
	inp = f()
	s = 0
	for i in inp[0:n:2]:
		s += i
	ans = cur = 0
	for i in range(1, n, 2):
		cur += inp[i] - inp[i - 1]
		if cur < 0:
			cur = 0
		ans = max(ans, cur)
	cur = 0
	for i in range(2, n, 2):
		cur += inp[i - 1] - inp[i]
		if cur < 0:
			cur = 0
		ans = max(ans, cur)
	ans += s
	res.append(ans)
print('\n'.join(map(str, res)))


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	n = int(input())
	l = list([int(x) for x in input().split()])
	sum = 0
	for i in range(n):
		if i % 2 == 0:
			sum += l[i]
	ar1 = []
	ar2 = []
	for i in range(0, n - 1, 2):
		ar1.append(l[i + 1] - l[i])
	s1 = 0
	s2 = 0
	res1 = -1 * 1000000007
	for i in range(len(ar1)):
		s1 += ar1[i]
		res1 = max(res1, s1)
		if s1 < 0:
			s1 = 0
	for i in range(2, n, 2):
		ar2.append(l[i - 1] - l[i])
	res2 = -1 * 1000000007
	for i in range(len(ar2)):
		s2 += ar2[i]
		res2 = max(res2, s2)
		if s2 < 0:
			s2 = 0
	sum += max(0, res1, res2)
	print(sum)


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import heapify, heappop, heappush
from statistics import median
from math import gcd, sqrt, floor, factorial, ceil, log2, log10
import copy
from copy import deepcopy
import sys
sys.setrecursionlimit(10 ** 7)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def get_list():
	return list(map(int, input().split()))

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def get_int():
	return int(input())
t = get_int()
for i in range(t):
	n = get_int()
	l = get_list()
	suma = sum(l[::2])
	maxa = 0
	ans = 0
	for i in range(1, n, 2):
		maxa = max(0, maxa + l[i] - l[i - 1])
		ans = max(ans, maxa)
	maxa = 0
	for i in range(1, n - 1, 2):
		maxa = max(0, maxa + l[i] - l[i + 1])
		ans = max(ans, maxa)
	print(suma + ans)


from sys import stdin, stdout

def kadane(arr):
	globalsum = float('-inf')
	currentsum = 0
	for i in arr:
		currentsum += i
		currentsum = max(currentsum, i)
		if currentsum > globalsum:
			globalsum = currentsum
	return globalsum
t = int(input())
for _ in range(t):
	n = int(stdin.readline())
	l = [int(x) for x in stdin.readline().split()]
	evensum = 0
	for i in range(0, n, 2):
		evensum += l[i]
	evenlist = []
	oddlist = []
	for i in range(0, n - 1, 2):
		evenlist.append(l[i + 1] - l[i])
	for i in range(1, n - 1, 2):
		oddlist.append(l[i] - l[i + 1])
	stdout.write(str(max(evensum, evensum + kadane(evenlist), evensum + kadane(oddlist))) + '\n')


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	real_max = 0
	sum = 0
	real_sum = 0
	for i in range(n // 2):
		sum += a[2 * i + 1] - a[2 * i]
		real_sum += a[2 * i]
		sum = max(sum, 0)
		if sum > real_max:
			real_max = sum
	if n % 2:
		real_sum += a[-1]
	sum = 0
	for i in range(1, (n + 1) // 2):
		sum += a[2 * i - 1] - a[2 * i]
		sum = max(sum, 0)
		if sum > real_max:
			real_max = sum
	print(real_sum + real_max)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
con = 10 ** 9 + 7
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = getlist()
		Arev = list(reversed(A))
		M = int(N // 2)
		if N == 1:
			print(A[0])
			continue
		anspre = sum(A)
		for i in range(M):
			anspre -= A[2 * i + 1]
		S = [0] * (M + 1)
		minval = 0
		valmax = 0
		for i in range(M):
			S[i + 1] = A[2 * i + 1] - A[2 * i]
		for i in range(M):
			S[i + 1] += S[i]
			minval = min(S[i + 1], minval)
			valmax = max(S[i + 1] - minval, valmax)
		M2 = int((N - 1) // 2)
		S2 = [0] * (M2 + 1)
		minval2 = 0
		valmax2 = 0
		for i in range(M2):
			S2[i + 1] = A[2 * i + 1] - A[2 * i + 2]
		for i in range(M2):
			S2[i + 1] += S2[i]
			minval2 = min(S2[i + 1], minval2)
			valmax2 = max(S2[i + 1] - minval2, valmax2)
		ans = anspre + max(valmax, valmax2)
		print(ans)
main()


from sys import exit, stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]

def maxsum(b):
	cur = r = 0
	for x in b:
		cur += x
		if cur < 0:
			cur = 0
		elif cur > r:
			r = cur
	return r
(T,) = rl()
for _ in range(T):
	(n,) = rl()
	a = rl()
	print(sum(a[::2]) + max((maxsum(b) for b in [[a[i] - a[i - 1] for i in range(1, n, 2)], [a[i - 1] - a[i] for i in range(2, n, 2)]])))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far
from math import *
for _ in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	a = []
	b = []
	s = 0
	for i in range(1, n, 2):
		a.append(num[i] - num[i - 1])
	for i in range(1, n - 1, 2):
		b.append(num[i] - num[i + 1])
	for i in range(0, n, 2):
		s += num[i]
	print(s + max(kadane(a), kadane(b)))


tests = int(input())
for tst in range(tests):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = sum([a[i] for i in range(0, n, 2)])
	b1 = [a[i] - a[i - 1] for i in range(1, n, 2)]
	(m1, s1) = (0, 0)
	for i in range(len(b1)):
		s1 += b1[i]
		m1 = max(m1, s1)
		if s1 < 0:
			s1 = 0
	b2 = [a[i] - a[i + 1] for i in range(1, n - 1, 2)]
	(m2, s2) = (0, 0)
	for i in range(len(b2)):
		s2 += b2[i]
		m2 = max(m2, s2)
		if s2 < 0:
			s2 = 0
	print(max([ans, ans + m1, ans + m2]))


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def f(a):
	M = 1000000007
	res = -1 * M
	sum = 0
	for i in range(len(a)):
		sum += a[i]
		res = max(res, sum)
		if sum < 0:
			sum = 0
	return res
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		if i % 2 == 0:
			sum += a[i]
	arr1 = []
	mn = 98
	nn = 98
	arr2 = []
	raj = 1
	for i in range(0, n - 1, 2):
		arr1.append(a[i + 1] - a[i])
	for i in range(2, n, 2):
		arr2.append(a[i - 1] - a[i])
	sum += max(0, max(f(arr1), f(arr2)))
	print(sum - raj + 1)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	base = sum(aa[::2])
	bb = []
	for i in range(0, n - 1, 2):
		bb.append(aa[i + 1] - aa[i])
	me = 0
	mx = 0
	for b in bb:
		me = max(me + b, 0)
		mx = max(mx, me)
	bb = []
	for i in range(1, n - 1, 2):
		bb.append(aa[i] - aa[i + 1])
	me = 0
	for b in bb:
		me = max(me + b, 0)
		mx = max(mx, me)
	print(base + mx)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = extra = 0
	s = [0, 0]
	mn = [10000000000.0, 10000000000.0]
	t = 0
	for i in range(n):
		s[t] += a[i]
		if t == 0:
			ans += a[i]
		diff = s[1] - s[0]
		extra = max(extra, diff)
		mn[t] = min(mn[t], diff)
		extra = max(extra, diff - mn[t])
		t ^= 1
	print(ans + extra)


import sys
import math
from collections import defaultdict, deque
import heapq
mod = 10 ** 9 + 7
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	if n == 1:
		print(arr[0])
		continue
	if n == 2:
		print(max(arr[0], arr[1]))
		continue
	even = []
	odd = []
	for i in range(2, n, 2):
		even.append(-arr[i] + arr[i - 1])
	for i in range(1, n, 2):
		odd.append(arr[i] - arr[i - 1])
	s = 0
	for i in range(0, n, 2):
		s += arr[i]
	maxs = 0
	res = 0
	(m, k) = (len(even), len(odd))
	for i in range(m):
		if res + even[i] >= 0:
			res += even[i]
			maxs = max(maxs, res)
		else:
			res = 0
	res = 0
	for i in range(k):
		if res + odd[i] >= 0:
			res += odd[i]
			maxs = max(maxs, res)
		else:
			res = 0
	s += maxs
	print(s)


def getMaxSubSum(arr):
	maxSum = 0
	partialSum = 0
	for item in arr:
		partialSum += item
		maxSum = max(maxSum, partialSum)
		if partialSum < 0:
			partialSum = 0
	return maxSum
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	dif0 = list()
	dif1 = list()
	s = 0
	for i in range(n // 2):
		s += a[2 * i]
		dif0.append(a[2 * i + 1] - a[2 * i])
	if n % 2 == 1:
		s += a[-1]
	for i in range((n - 1) // 2):
		dif1.append(a[2 * i + 1] - a[2 * i + 2])
	print(s + max(getMaxSubSum(dif0), getMaxSubSum(dif1)))


for t in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	dp = [[0] * 3 for _ in range(n + 2)]
	for i in range(n):
		dp[i + 1][0] = dp[i][0] + (a[i] if i % 2 == 0 else 0)
		if i + 1 < n:
			dp[i + 2][1] = max(dp[i][0], dp[i][1]) + (a[i + 1] if i % 2 == 0 else a[i])
		dp[i + 1][2] = max(dp[i][1], dp[i][2]) + (a[i] if i % 2 == 0 else 0)
	print(max(dp[n]))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(temp, mx, ans) = (0, 0, 0)
	for i in range(0, n, 2):
		ans += l[i]
	for i in range(0, n - 1, 2):
		temp += l[i + 1] - l[i]
		mx = max(mx, temp)
		if temp < 0:
			temp = 0
	temp = 0
	for i in range(1, n - 1, 2):
		temp += l[i] - l[i + 1]
		mx = max(mx, temp)
		if temp < 0:
			temp = 0
	print(ans + mx)


from collections import *
import sys
from bisect import *
input = sys.stdin.readline
from math import *
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	(eve, odd) = ([], [])
	for i in range(n):
		if i % 2 == 0:
			eve.append(a[i])
		else:
			odd.append(a[i])
	diff1 = []
	for i in range(min(len(eve), len(odd))):
		diff1.append(odd[i] - eve[i])
	diff2 = []
	for i in range((n - 1) // 2):
		diff2.append(odd[i] - eve[i + 1])
	ma = -float('inf')
	maxe = 0
	for i in diff1:
		maxe += i
		if ma < maxe:
			ma = maxe
		if maxe < 0:
			maxe = 0
	ma1 = -float('inf')
	maxe1 = 0
	for i in diff2:
		maxe1 += i
		if ma1 < maxe1:
			ma1 = maxe1
		if maxe1 < 0:
			maxe1 = 0
	y = max(sum(eve), sum(odd))
	print(max(y, sum(eve) + max(ma1, ma)))


import sys
from collections import defaultdict as dd
input = sys.stdin.readline

def kadane(arr):
	summ = 0
	maxi = 0
	for i in arr:
		summ += i
		if summ < 0:
			summ = 0
		else:
			maxi = max(maxi, summ)
	return maxi
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = []
	arr2 = []
	ans = 0
	for i in range(0, n, 2):
		ans += arr[i]
	for i in range(1, n - 1, 2):
		arr1 += [arr[i] - arr[i + 1]]
	for i in range(0, n - 1, 2):
		arr2 += [arr[i + 1] - arr[i]]
	a = kadane(arr1)
	b = kadane(arr2)
	print(ans + max(a, b))


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from copy import copy
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		ar.insert(0, 0)
		if n % 2 == 1:
			ar.append(0)
		ans = 0
		for k in range(2):
			even = 0
			cr = []
			for i in range(len(ar)):
				if i % 2 == 1:
					even += ar[i]
				elif i != 0:
					cr.append(ar[i] - ar[i - 1])
			ct = 0
			dif = 0
			sum = 0
			for i in cr:
				ct += i
				dif = min(dif, ct)
				sum = max(sum, ct - dif)
			ans = max(ans, even + sum)
			ar = ar[::-1]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l1 = []
	l2 = []
	sm = 0
	for i in range(1, n - 1, 2):
		sm += a[i - 1]
		l1.append(a[i] - a[i - 1])
		l2.append(a[i] - a[i + 1])
	if n % 2 == 0:
		sm += a[-2]
		l1.append(a[-1] - a[-2])
	else:
		sm += a[-1]
	ct = 0
	x = -math.inf
	for i in l1:
		ct += i
		x = max(x, ct)
		ct = max(0, ct)
	ans1 = max(x, 0)
	ct = 0
	x = -math.inf
	for i in l2:
		ct += i
		x = max(x, ct)
		ct = max(0, ct)
	ans2 = max(x, 0)
	print(sm + max(ans1, ans2))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		return
	bst = 0
	bi1 = 0
	bi2 = 0
	end = -1
	ei1 = 0
	k = 0
	api1 = 0
	ap1 = []
	ap2 = []
	for (i, x) in enumerate(a):
		if k:
			ap1.append(x - api)
			k = 0
		else:
			api = x
			k = 1
	k = 0
	for (i, x) in enumerate(a):
		if i == 0:
			continue
		if k:
			ap2.append(api - x)
			k = 0
		else:
			api = x
			k = 1
	bst = 0
	end = 0
	for p in ap1:
		if p > 0:
			end += p
		elif end + p > 0:
			bst = max(end, bst)
			end += p
		else:
			end = 0
		bst = max(bst, end)
	end = 0
	for p in ap2:
		if p > 0:
			end += p
		elif end + p > 0:
			bst = max(end, bst)
			end += p
		else:
			end = 0
		bst = max(bst, end)
	s = 0
	for (i, x) in enumerate(a):
		if i % 2 == 0:
			s += x
	print(s + bst)
t = int(input())
for _ in range(t):
	solve()


t = int(input())

def rec(mn, ind, l, b, dp):
	if ind == 0:
		return 0
	else:
		if dp[ind - 1] == 0:
			if mn[ind - 1][0] < l and mn[ind - 1][1] < b:
				dp[ind - 1] = max(rec(mn, ind - 1, l, b, dp), mn[ind - 1][2] + rec(mn, ind - 1, mn[ind - 1][0], mn[ind - 1][1], dp))
			else:
				dp[ind - 1] = rec(mn, ind - 1, l, b, dp)
		return dp[ind - 1]
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	sm = 0
	mx = 0
	for i in range(0, len(l) - 1, 2):
		sm += l[i + 1] - l[i]
		mx = max(sm, mx)
		if sm < 0:
			sm = 0
	sm1 = 0
	mx1 = 0
	for i in range(1, len(l) - 1, 2):
		sm1 += l[i] - l[i + 1]
		mx1 = max(sm1, mx1)
		if sm1 < 0:
			sm1 = 0
	print(sum(l[::2]) + max(mx, mx1))


def solve(nums):
	best = 0
	cur = 0
	for x in nums:
		cur += x
		best = max(cur, best)
		cur = max(cur, 0)
	return best
for _ in range(int(input())):
	input()
	seq = list(map(int, input().split()))
	base = 0
	diff1 = []
	diff2 = []
	for x in range(0, len(seq), 2):
		base += seq[x]
		if x + 1 < len(seq):
			diff1.append(seq[x + 1] - seq[x])
		if x > 0:
			diff2.append(seq[x - 1] - seq[x])
	print(base + max(solve(diff1), solve(diff2)))


from math import ceil

def solve():
	n = int(input())
	L = list(map(int, input().split()))
	E = [0] * n
	O = [0] * n
	E[0] = L[0]
	O[0] = 0
	res = L[0]
	for i in range(1, n):
		if i % 2 == 0:
			E[i] = E[i - 1] + L[i]
			O[i] = O[i - 1]
			res += L[i]
		else:
			E[i] = E[i - 1]
			O[i] = O[i - 1] + L[i]
	md = 0
	s = 0
	for i in range(1, n, 2):
		if s < 0:
			s = 0
		cr = L[i] - L[i - 1]
		s += cr
		md = max(md, s)
	md = max(md, s)
	s = 0
	for i in range(2, n, 2):
		if s < 0:
			s = 0
		cr = L[i - 1] - L[i]
		s += cr
		md = max(md, s)
	md = max(md, s)
	print(res + md)
for cnt in range(int(input())):
	solve()


for t in range(int(input())):
	n = int(input())
	A = input().split(' ')
	for j in range(n):
		A[j] = int(A[j])
	k = int((n - 1) / 2)
	evfree = 0
	evnon = 0
	odfree = 0
	odnon = 0
	for i in range(k):
		evnon = max(evnon - A[2 * i] + A[2 * i + 1], 0)
		odnon = max(odnon - A[2 * i + 2] + A[2 * i + 1], 0)
		evfree = max(evfree, evnon)
		odfree = max(odfree, odnon)
	if n % 2 == 0:
		evnon = max(evnon - A[2 * k] + A[2 * k + 1], 0)
		evfree = max(evfree, evnon)
	ans = 0
	for i in range(k + 1):
		ans += A[2 * i]
	print(ans + max(evfree, odfree))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		even_sum = 0
		for (i, v) in enumerate(a):
			if i % 2 == 0:
				even_sum += v
		temp = 0
		best = 0
		for i in range(1, n - 1, 2):
			temp += a[i] - a[i + 1]
			if temp < 0:
				temp = 0
			best = max(best, temp)
		after_sum = even_sum + best
		temp = best = 0
		for i in range(0, n - 1, 2):
			temp += a[i + 1] - a[i]
			if temp < 0:
				temp = 0
			best = max(best, temp)
		before_sum = even_sum + best
		ans = max(even_sum, after_sum, before_sum)
		print(ans)
main()


def maiorLucro(arr):
	maior = soma = 0
	for x in arr:
		soma += x
		if soma < 0:
			soma = 0
		if soma > maior:
			maior = soma
	return maior

def solve():
	input()
	num = list(map(int, input().split()))
	prefImp = [j - i for (i, j) in zip(num[0::2], num[1::2])]
	prefPar = [i - j for (i, j) in zip(num[1::2], num[2::2])]
	maxImp = maiorLucro(prefImp)
	maxPar = maiorLucro(prefPar)
	adicional = max(maxImp, maxPar)
	print(sum(num[::2]) + (adicional if adicional > 0 else 0))
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if n % 2 == 0:
		diff = []
		su = 0
		for i in range(0, n, 2):
			su += lis[i]
			diff.append(lis[i] - lis[i + 1])
		mi = 0
		fi = 0
		for i in range(n // 2):
			fi += diff[i]
			if fi < 0:
				if fi < mi:
					mi = fi
			else:
				fi = 0
		m1 = su - mi
		dif2 = []
		for i in range(1, n - 1, 2):
			dif2.append(lis[i] - lis[i + 1])
		ma = 0
		fi = 0
		for i in range(len(dif2)):
			fi += dif2[i]
			if fi > 0:
				if fi > ma:
					ma = fi
			else:
				fi = 0
		m2 = su + ma
		print(max(m1, m2))
	else:
		su = 0
		su += lis[-1]
		dif1 = []
		for i in range(0, n - 1, 2):
			su += lis[i]
			dif1.append(lis[i] - lis[i + 1])
		mi = 0
		fi = 0
		for i in range(n // 2):
			fi += dif1[i]
			if fi < 0:
				if fi < mi:
					mi = fi
			else:
				fi = 0
		m1 = su - mi
		dif2 = []
		for i in range(1, n, 2):
			dif2.append(lis[i] - lis[i + 1])
		ma = 0
		fi = 0
		for i in range(len(dif2)):
			fi += dif2[i]
			if fi > 0:
				if fi > ma:
					ma = fi
			else:
				fi = 0
		m2 = su + ma
		print(max(m1, m2))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	if n == 1:
		print(a[0])
		continue
	d = [[0, 1]]
	for i in range(len(d), n):
		if i % 2 == 1:
			d_i = a[i] - a[i - 1]
		else:
			d_i = a[i - 1] - a[i]
		l_i = 2
		if len(d) >= 2:
			if d[-2][0] > 0:
				d_i += d[-2][0]
				l_i += d[-2][1]
		d.append([d_i, l_i])
	d1 = [a[0]]
	for i in range(len(d1), n):
		if i % 2 == 0:
			d1.append(d1[-1] + a[i])
		else:
			d1.append(d1[-1])
	ans = d1[-1]
	for i in range(n):
		(d_i, l_i) = d[i]
		ans = max(ans, d1[-1] + d_i)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	inp = list(map(int, input().split()))
	if n == 1:
		print(inp[0])
	else:
		lef = [0]
		ri = [max(0, inp[1] - inp[0])]
		for i in range(1, len(inp)):
			if i % 2 == 1:
				lef.append(0)
				ri.append(0)
				continue
			if i - 2 >= 0:
				lef.append(max(0, lef[-2] + inp[i - 1] - inp[i]))
			else:
				lef.append(max(0, inp[i - 1] - inp[i]))
			if i + 1 < len(inp):
				if i - 2 >= 0:
					ri.append(max(0, ri[-2] + inp[i + 1] - inp[i]))
				else:
					ri.append(max(0, inp[i + 1] - inp[i]))
		ans = 0
		for i in range(0, len(inp), 2):
			ans += inp[i]
		ans += max(max(ri), max(lef))
		print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def kadane(A):
	t = -100000000000
	s = 0
	for x in A:
		t = max(x, t + x)
		s = max(s, t)
	return s
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	diff1 = [arr[x] - arr[x - 1] for x in range(1, n, 2)]
	diff2 = [arr[x - 1] - arr[x] for x in range(2, n, 2)]
	ans = sum([arr[x] for x in range(0, n, 2)])
	temp1 = kadane(diff1)
	temp2 = kadane(diff2)
	temp = max(temp1, temp2)
	if temp > 0:
		ans += temp
	print(ans)


def max_subarray_sum(arr):
	best = 0
	curr = 0
	for num in arr:
		curr = max(0, curr + num)
		best = max(curr, best)
	return best
t = int(input().split()[0])
for case in range(t):
	n = int(input().split()[0])
	arr = list(map(int, input().split()))
	sumEvens = sum(arr[::2])
	evens = []
	odds = []
	for i in range(0, len(arr) - 1):
		if i % 2 == 0:
			evens.append(arr[i + 1] - arr[i])
		else:
			odds.append(arr[i] - arr[i + 1])
	print(sumEvens + max(max_subarray_sum(evens), max_subarray_sum(odds)))


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre
maxint = 10 ** 24

def kadane(a, size):
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for _ in range(inin()):
	n = inin()
	a = ain()
	ans = sum(a[0:n:2])
	l3 = []
	l4 = []
	for i in range(0, n - 1, 2):
		l3 += [a[i + 1] - a[i]]
	for i in range(1, n - 1, 2):
		l4 += [a[i] - a[i + 1]]
	print(max(kadane(l3, len(l3)), kadane(l4, len(l4)), 0) + ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	li = []
	for i in range(1, n, 2):
		li.append(ar[i] - ar[i - 1])
	sm = [0]
	counter = 0
	for i in li:
		counter += i
		if counter < 0:
			counter = 0
		else:
			sm.append(counter)
	ans1 = max(sm)
	ans = 0
	li = []
	if n > 2:
		for i in range(2, n, 2):
			ans += ar[i]
			li.append(ar[i - 1] - ar[i])
	sm = [0]
	counter = 0
	for i in li:
		counter += i
		if counter < 0:
			counter = 0
		else:
			sm.append(counter)
	ans2 = max(sm)
	ans += ar[0]
	print(ans + max(ans1, ans2))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	es = 0
	for i in range(0, n, 2):
		es += a[i]
	(e, o) = (0, 0)
	(me, mo) = (10 ** 18, 0)
	ans = -10 ** 18
	for i in range(n):
		if i % 2 == 0:
			e += a[i]
		else:
			o += a[i]
		if i % 2 == 0:
			me = min(me, o - e)
			ans = max(ans, es + o - e - me)
		else:
			mo = min(mo, o - e)
			ans = max(ans, es + o - e - mo)
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import *
import bisect
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'

def fn(n):
	c = 0
	while n % 2 == 0:
		c += 1
		n //= 2
	return c

def maxSubArraySum(a, size):
	max_so_far = -1000000000.0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		if n == 1:
			print(sum(a))
			continue
		l1 = []
		l2 = []
		x = 0
		for i in range(n):
			if i % 2 == 0:
				x += a[i]
		for i in range(n):
			if i % 2 == 0:
				if i == 0:
					l1.append(-1000000000.0)
					l2.append(a[i + 1] - a[i])
				elif i == n - 1:
					l1.append(a[i - 1] - a[i])
					l2.append(-1000000000.0)
				else:
					l1.append(a[i - 1] - a[i])
					l2.append(a[i + 1] - a[i])
		c = maxSubArraySum(l1, len(l1))
		d = maxSubArraySum(l2, len(l2))
		f = max(c, d)
		ans = x
		if f > 0:
			ans += f
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def helper(A):
	MIN = []
	MAX = []
	temp_min = max(A) + 1
	for i in range(len(A)):
		temp_min = min(temp_min, A[i])
		MIN += [temp_min]
	temp_max = min(A) - 1
	A = A[::-1]
	for i in range(len(A)):
		temp_max = max(temp_max, A[i])
		MAX += [temp_max]
	MAX = MAX[::-1]
	ans = A[0] - A[-1]
	for i in range(len(A) - 1):
		ans = max(ans, MAX[i + 1] - MIN[i])
	return ans

def find(A):
	pre_even = []
	pre_odd = []
	temp_even = 0
	temp_odd = 0
	for i in range(len(A)):
		if i % 2 == 0:
			temp_even += A[i]
		else:
			temp_odd += A[i]
		pre_even += [temp_even]
		pre_odd += [temp_odd]
	ans_odd = [0]
	ans_even = []
	for i in range(len(A)):
		if i % 2 == 0:
			ans_even += [pre_odd[i] - pre_even[i]]
		else:
			ans_odd += [pre_odd[i] - pre_even[i]]
	ans1 = helper(ans_odd)
	ans2 = helper(ans_even)
	return max(pre_even[-1] + ans1, pre_even[-1] + ans2, pre_even[-1])
for _ in range(int(input())):
	input()
	A = list(map(int, input().strip().split()))
	print(find(A))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())

def max_subarray(numbers):
	best_sum = 0
	current_sum = 0
	for x in numbers:
		current_sum = max(0, current_sum + x)
		best_sum = max(best_sum, current_sum)
	return best_sum
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += a[i]
	b = []
	c = []
	for i in range(n - 1):
		if i % 2 == 0:
			b.append(a[i + 1] - a[i])
		else:
			c.append(a[i] - a[i + 1])
	print(ans + max(max_subarray(b), max_subarray(c)))


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	n = int(input().strip())
	a = [int(x) for x in input().strip().split()]
	alen = len(a)
	if alen % 2:
		a.append(0)
		alen += 1
	os = 0
	cs = 0
	ts = 0
	for i in range(0, alen, 2):
		os += a[i]
	for i in range(alen // 2):
		cn = a[2 * i + 1] - a[2 * i]
		cs = max(cs + cn, cn)
		ts = max(cs, ts)
	cs = 0
	for i in range(1, alen - 1, 2):
		cn = a[i] - a[i + 1]
		cs = max(cs + cn, cn)
		ts = max(ts, cs)
	print(os + ts)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	o = 0
	e = 0
	c = 0
	s = 0
	m = 0
	for i in range(n):
		c += 1
		if i % 2 == 0:
			e += l[i]
			s += l[i]
		else:
			o += l[i]
		if c % 2 == 0:
			if o - e > m:
				m = o - e
			if e > o:
				e = 0
				o = 0
				c = 0
	c = 0
	e = 0
	o = 0
	for i in range(1, n):
		c += 1
		if i % 2 == 0:
			e += l[i]
		else:
			o += l[i]
		if c % 2 == 0:
			if o - e > m:
				m = o - e
			if e > o:
				e = 0
				o = 0
				c = 0
	print(s + m)


def solve():
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += a[i]
	v = list()
	for i in range(n - 1):
		if i % 2 == 0:
			v.append(a[i + 1] - a[i])
	max_sum = 0
	cur = 0
	for i in v:
		cur += i
		max_sum = max(max_sum, cur)
		cur = max(cur, 0)
	tmp = max_sum
	v.clear()
	for i in range(n - 1):
		if i % 2 == 1:
			v.append(a[i] - a[i + 1])
	max_sum = 0
	cur = 0
	for i in v:
		cur += i
		max_sum = max(max_sum, cur)
		cur = max(cur, 0)
	ans += max(max_sum, tmp)
	print(ans)
t = int(input())
while t > 0:
	t -= 1
	solve()


def maxXsum(A, l, m, r):
	x = 0
	left = -1000000007
	for i in range(m, l - 1, -1):
		x = x + A[i]
		if x > left:
			left = x
	x = 0
	right = -1000000007
	for i in range(m + 1, r + 1):
		x = x + A[i]
		if x > right:
			right = x
	return max(left + right, left, right)

def maxsubsum(A, l, r):
	if l == r:
		return A[l]
	m = (l + r) // 2
	return max(maxsubsum(A, l, m), maxsubsum(A, m + 1, r), maxXsum(A, l, m, r))
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans = ans + A[i]
	L = [0]
	R = [0]
	for i in range(n):
		if i % 2 == 1:
			continue
		if i < n - 1:
			R.append(A[i + 1] - A[i])
		if i > 0:
			L.append(A[i - 1] - A[i])
	print(max(ans, ans + maxsubsum(L, 0, len(L) - 1), ans + maxsubsum(R, 0, len(R) - 1)))


def kadane(arr):
	max_end = 0
	max_far = -float('inf')
	for i in arr:
		max_end = max_end + i
		max_far = max(max_far, max_end)
		if max_end < 0:
			max_end = 0
	return max_far
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pre = []
	suf = []
	su = 0
	for i in range(0, n, 2):
		su += arr[i]
		if i + 1 < n:
			pre.append(arr[i + 1] - arr[i])
		if i + 2 < n:
			suf.append(arr[i + 1] - arr[i + 2])
	print(su + max(kadane(pre), kadane(suf), 0))


from sys import stdin
for _ in range(int(stdin.readline().rstrip())):
	n = int(stdin.readline().rstrip())
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	a = [0] * (n // 2)
	x = [0] * ((n - 1) // 2)
	t = 0
	j = 0
	if n % 2:
		t = l[-1]
	for i in range(0, n - 1, 2):
		t += l[i]
		a[j] = l[i + 1] - l[i]
		j += 1
	j = 0
	for i in range(1, n - 1, 2):
		x[j] = l[i] - l[i + 1]
		j += 1
	s = b = 0
	for i in range(len(a)):
		s = max(a[i], s + a[i])
		b = max(s, b)
	s = 0
	for i in range(len(x)):
		s = max(x[i], s + x[i])
		b = max(s, b)
	print(t + b)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	(v1, v2, v3, v4) = (0, 0, 0, 0)
	for (i, j) in enumerate(a):
		if i >= 1:
			if i % 2 == 1:
				v3 = max(a[i] - a[i - 1], a[i] - a[i - 1] + v1, v3)
			else:
				v3 = max(a[i - 1] - a[i], a[i - 1] - a[i] + v1, v3)
			v4 = max(v4, v3)
			(v1, v2, v3) = (v2, v3, 0)
	print(sum((a[i] for i in range(0, n, 2))) + v4)


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def max_subarray(numbers):
	best_sum = 0
	current_sum = 0
	for x in numbers:
		current_sum = max(0, current_sum + x)
		best_sum = max(best_sum, current_sum)
	return best_sum

def slv(N, A):
	from itertools import accumulate
	ans = sum(A[::2])
	b = []
	for i in range(0, N - 1, 2):
		b.append(A[i + 1] - A[i])
	c = []
	for i in range(1, N - 1, 2):
		c.append(A[i] - A[i + 1])
	ans += max(max_subarray(b), max_subarray(c))
	return ans

def main():
	for _ in range(read_int()):
		N = read_int()
		A = read_int_n()
		print(slv(N, A))
main()


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())

def maxSubArraySum(a, size):
	max_so_far = -0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	e = []
	o = []
	su = 0
	for i in range(0, n, 2):
		su += a[i]
	for i in range(0, n - 1, 2):
		e.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		o.append(a[i] - a[i + 1])
	mx1 = maxSubArraySum(e, len(e))
	mx2 = maxSubArraySum(o, len(o))
	mx = max([mx1, mx2, 0])
	print(mx + su)


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	n = int(inp())
	a = list(map(int, inp().split()))
	e = [0] * n
	o = [0] * n
	e[0] = a[0]
	suf = [0] * (n + 1)
	for i in range(1, n):
		if i % 2 == 0:
			e[i] = a[i] + e[i - 1]
			o[i] += o[i - 1]
		else:
			o[i] = a[i] + o[i - 1]
			e[i] += e[i - 1]
	for i in range(n - 1, -1, -1):
		suf[i] = suf[i + 1]
		if i % 2 == 0:
			suf[i] += a[i]
	b = [0] * n
	for i in range(n):
		b[i] = o[i] - e[i]
	om = 10000000000.0
	em = 10000000000.0
	ans = max(0, max(b))
	for i in range(n):
		if i % 2 == 0:
			ans = max(ans, b[i] - em)
			em = min(em, b[i])
		else:
			ans = max(ans, b[i] - om)
			om = min(om, b[i])
	print(e[n - 1] + ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def maxSubArraySum(a, size):
	if not size or not a:
		return 0
	max_so_far = -10 ** 18
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		continue
	b = []
	b2 = []
	orig = 0
	for i in range(0, n, 2):
		orig += a[i]
		if i != 0:
			b2 += [-a[i] + a[i - 1]]
	for i in range(1, n, 2):
		b += [a[i] - a[i - 1]]
	if max(b) <= 0 and (b2 and max(b2) <= 0):
		print(orig)
		continue
	print(orig + max(maxSubArraySum(b, len(b)), maxSubArraySum(b2, len(b2))))


def maxSubArraySum(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_ending_here < 0:
			max_ending_here = 0
		elif max_so_far < max_ending_here:
			max_so_far = max_ending_here
	return max_so_far
for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	sev = 0
	for i in range(len(l)):
		if i % 2 == 0:
			sev += l[i]
	i = 0
	a = []
	while i + 1 < len(l):
		a.append(l[i + 1] - l[i])
		i += 2
	i = 1
	b = []
	while i + 1 < len(l):
		b.append(l[i] - l[i + 1])
		i += 2
	y = max(maxSubArraySum(a, len(a)), maxSubArraySum(b, len(b)))
	print(sev + y)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def toogle(char):
	if char == 'b':
		return 'w'
	else:
		return 'b'

def take(lis):
	l = -10 ** 9 + 7
	ans = -10 ** 9 + 7
	for i in range(len(lis)):
		l = max(lis[i], lis[i] + l)
		ans = max(ans, l)
	return ans

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = inar()
		even_sum = 0
		for i in range(n):
			if i % 2 == 0:
				even_sum += arr[i]
		even = []
		odd = []
		for i in range(n):
			if i % 2 == 0 and i + 1 < n:
				even.append(arr[i + 1] - arr[i])
			elif i + 1 < n:
				odd.append(arr[i] - arr[i + 1])
		print(even_sum + max(0, take(odd), take(even)))
main()


def get(a):
	dp = [0] * len(a)
	if len(a) >= 1:
		dp[0] = max(dp[0], a[0])
		for i in range(1, len(a)):
			dp[i] = max(0, dp[i - 1] + a[i])
		return max(dp)
	return 0
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += arr[i]
	even = []
	odd = []
	for i in range(0, n - 1, 2):
		even.append(arr[i + 1] - arr[i])
	for i in range(1, n - 1, 2):
		odd.append(arr[i] - arr[i + 1])
	x = get(even)
	y = get(odd)
	ans += max(0, x, y)
	print(ans)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 10 ** 9 + 7
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	s = 0
	for i in range(n):
		if i % 2 == 0:
			s += a[i]
	mx_sum = 0
	cur_sum = 0
	for i in range(0, n - n % 2, 2):
		cur_sum = max(0, cur_sum + a[i + 1] - a[i])
		mx_sum = max(cur_sum, mx_sum)
	cur_sum = 0
	for i in range(1, n - (n % 2 == 0), 2):
		cur_sum = max(0, cur_sum + a[i] - a[i + 1])
		mx_sum = max(cur_sum, mx_sum)
	print(mx_sum + s)


for _ in range(int(input())):
	n = int(input())
	a = arr = list(map(int, input().split()))
	ss = 0
	odd = []
	even = []
	for i in range(0, n - 1, 2):
		even.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		odd.append(a[i] - a[i + 1])
	ans = 0
	total = 0
	for i in range(len(even)):
		total += even[i]
		if total < 0:
			total = 0
		ans = max(ans, total)
	total = 0
	for i in range(len(odd)):
		total += odd[i]
		if total < 0:
			total = 0
		ans = max(ans, total)
	for i in range(0, n, 2):
		ss += arr[i]
	print(ss + ans)


def solve(s, e, a, mul):
	maxi = 0
	prev = 0
	for i in range(s, e, 2):
		prev = max(prev + mul * (a[i + 1] - a[i]), mul * (a[i + 1] - a[i]))
		maxi = max(maxi, prev)
	return maxi
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	total = sum((a[i] for i in range(0, n, 2)))
	ans = total + solve(0, n - n % 2, a, 1)
	if n % 2 != 0:
		ans = max(ans, total + solve(1, n, a, -1))
	else:
		ans = max(ans, total + solve(1, n - 1, a, -1))
	print(ans)


import sys
sys.setrecursionlimit(10000)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even_sum = 0
	all_diffs_start = []
	all_diffs_non_start = []
	for i in range(n):
		if i % 2 == 0:
			even_sum += a[i]
		else:
			all_diffs_start.append(a[i] - a[i - 1])
			try:
				all_diffs_non_start.append(a[i] - a[i + 1])
			except:
				pass
	max_sum = 0
	curr_sum = 0
	for adiff in all_diffs_start:
		if curr_sum < 0:
			curr_sum = 0
		curr_sum += adiff
		if curr_sum > max_sum:
			max_sum = curr_sum
	curr_sum = 0
	for adiff in all_diffs_non_start:
		if curr_sum < 0:
			curr_sum = 0
		curr_sum += adiff
		if curr_sum > max_sum:
			max_sum = curr_sum
	print(even_sum + max_sum)


def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max, 0)
	return max(max_so_far, 0)
for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	temp1 = []
	temp2 = []
	if N == 1:
		print(A[0])
	elif N % 2 == 0:
		suma = 0
		for i in range(0, N, 2):
			temp1.append(A[i + 1] - A[i])
			suma += A[i]
		for i in range(1, N - 1, 2):
			temp2.append(A[i] - A[i + 1])
		t = maxSubArraySum(temp1, len(temp1))
		if len(temp2) == 0:
			t2 = 0
		else:
			t2 = maxSubArraySum(temp2, len(temp2))
		r = max(t, t2)
		print(r + suma)
	else:
		suma = 0
		for i in range(0, N - 1, 2):
			temp1.append(A[i + 1] - A[i])
			suma += A[i]
		suma += A[N - 1]
		for i in range(1, N, 2):
			temp2.append(A[i] - A[i + 1])
		t1 = maxSubArraySum(temp1, len(temp1))
		t2 = maxSubArraySum(temp2, len(temp2))
		r = max(t1, t2)
		print(suma + r)


def f(l):
	(res, end) = (0, 0)
	for i in range(len(l)):
		end += l[i]
		if end < 0:
			end = 0
		elif res < end:
			res = end
	return res
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	l2 = []
	s = l[0]
	for i in range(1, len(l)):
		if i % 2 == 0:
			s += l[i]
			l2.append(l[i - 1] - l[i])
		else:
			l1.append(l[i] - l[i - 1])
	print(s + max(f(l1), f(l2)))


import math
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for j in range(n):
		if j % 2 == 0:
			ans += arr[j]
	arr1 = []
	for j in range(1, n, 2):
		arr1.append(arr[j] - arr[j - 1])
	msf = 0
	meh = 0
	for j in range(len(arr1)):
		meh += arr1[j]
		if msf <= meh:
			msf = meh
		if meh < 0:
			meh = 0
	cur1 = ans + msf
	arr2 = []
	for j in range(2, n, 2):
		arr2.append(arr[j - 1] - arr[j])
	msf = 0
	meh = 0
	for j in range(len(arr2)):
		meh += arr2[j]
		if msf <= meh:
			msf = meh
		if meh < 0:
			meh = 0
	cur2 = ans + msf
	print(max(cur1, cur2))


t = int(input())

def task1(list1):
	ans = 0
	temp_ans = 0
	for i in range(1, n, 2):
		temp1 = list1[i - 1]
		temp2 = list1[i]
		temp_ans += temp2 - temp1
		if temp_ans <= 0:
			temp_ans = 0
		if temp_ans > ans:
			ans = temp_ans
	return ans

def task2(list1):
	ans = 0
	temp_ans = 0
	for i in range(2, n, 2):
		temp1 = list1[i - 1]
		temp2 = list1[i]
		temp_ans += temp1 - temp2
		if temp_ans <= 0:
			temp_ans = 0
		if temp_ans > ans:
			ans = temp_ans
	return ans
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	ans = 0
	for i in range(0, n, 2):
		ans += list1[i]
	ans1 = task1(list1)
	ans2 = task2(list1)
	print(ans + max(ans1, ans2))


t = int(input())
for hatt in range(t):
	n = int(input())
	lis = input().split()
	arr = []
	sum = 0
	for i in range(n):
		num = int(lis[i])
		if i % 2 == 0:
			sum += num
			arr.append(-num)
		else:
			arr.append(num)
	lis1 = []
	lis2 = []
	i = 1
	while i < n:
		lis1.append(arr[i] + arr[i - 1])
		i += 2
	i = 2
	while i < n:
		lis2.append(arr[i] + arr[i - 1])
		i += 2

	def maxsubsequence(lis):
		allmax = 0
		currmax = 0
		for i in lis:
			currmax += i
			if currmax < 0:
				currmax = 0
			else:
				allmax = max(currmax, allmax)
		return allmax
	print(sum + max(maxsubsequence(lis1), maxsubsequence(lis2)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ev = a[0:n:2]
	od = a[1:n:2]
	sa = [0]
	tmp = 0
	for i in range(len(od)):
		tmp = max(0, tmp + od[i] - ev[i])
		sa.append(tmp)
	if len(od) > len(ev):
		tmp += od[i + 1]
		sa.append(tmp)
	tmp = 0
	for i in range(len(ev) - 1):
		tmp = max(0, tmp + od[i] - ev[i + 1])
		sa.append(tmp)
	print(sum(ev) + max(sa))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	l = li()
	s = sum([l[i] for i in range(n) if not i & 1])
	curr = ans = anscheck = 0
	for i in range(0, n - 1, 2):
		temp = l[i + 1] - l[i]
		curr = temp if curr < 0 else curr + temp
		anscheck = max(anscheck, curr)
	ans = max(ans, anscheck + s)
	curr = 0
	anscheck = 0
	for i in range(1, n - 1, 2):
		temp = l[i] - l[i + 1]
		curr = temp if curr < 0 else curr + temp
		anscheck = max(anscheck, curr)
	ans = max(ans, s + anscheck)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ru = [0] * (n + 1)
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += a[i]
			ru[i + 1] = ru[i] - a[i]
		else:
			ru[i + 1] = ru[i] + a[i]
	li1 = [0]
	li2 = [0]
	for i in range(n):
		if i % 2 == 0:
			li1.append(ru[i + 1])
		else:
			li2.append(ru[i + 1])
	add = 0
	min_val = 0
	for val in li1:
		add = max(val - min_val, add)
		min_val = min(min_val, val)
	min_val = 0
	for val in li2:
		add = max(val - min_val, add)
		min_val = min(min_val, val)
	print(ans + add)


from __future__ import division, print_function
import os, sys, time
from io import BytesIO, IOBase
from itertools import accumulate
ONLINE_JUDGE = 1
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
start_time = time.time()

def maiorLucro(arr):
	maior = soma = 0
	for x in arr:
		soma += x
		if soma < 0:
			soma = 0
		if soma > maior:
			maior = soma
	return maior

def solve():
	i()
	num = il()
	prefImp = [j - i for (i, j) in zip(num[0::2], num[1::2])]
	prefPar = [i - j for (i, j) in zip(num[1::2], num[2::2])]
	maxImp = maiorLucro(prefImp)
	maxPar = maiorLucro(prefPar)
	adicional = max(maxImp, maxPar)
	print(sum(num[::2]) + (adicional if adicional > 0 else 0))

def main():
	t = ii()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Tempo :', time.time() - start_time, ' segundos')
		sys.stdout.close()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
i = input

def ii():
	return int(input())

def il():
	return list(map(int, input().split()))

def isr():
	return input().strip()

def im():
	return map(int, input().split())
global tt
if not ONLINE_JUDGE:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
main()


def kadane(arr):
	globalsum = float('-inf')
	currentsum = 0
	for i in arr:
		currentsum += i
		currentsum = max(currentsum, i)
		if currentsum > globalsum:
			globalsum = currentsum
	return globalsum
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	evensum = 0
	for i in range(0, n, 2):
		evensum += l[i]
	evenlist = []
	oddlist = []
	for i in range(0, n - 1, 2):
		evenlist.append(l[i + 1] - l[i])
	for i in range(1, n - 1, 2):
		oddlist.append(l[i] - l[i + 1])
	print(max(evensum, evensum + kadane(evenlist), evensum + kadane(oddlist)))


for _ in range(int(input())):
	n = int(input())
	u = list(map(int, input().split()))
	if n == 1:
		print(u[0])
		continue
	if n == 2:
		print(max(u))
		continue
	sm = 0
	for i in range(0, n, 2):
		sm += u[i]
	a1 = []
	for i in range(1, n, 2):
		a1.append(u[i] - u[i - 1])
	ans1 = a1[0]
	mn = 0
	cur = 0
	for i in range(len(a1)):
		cur += a1[i]
		ans1 = max(ans1, cur - mn)
		mn = min(mn, cur)
	u = u[1:]
	a1 = []
	for i in range(1, n - 1, 2):
		a1.append(u[i - 1] - u[i])
	ans2 = a1[0]
	mn = 0
	cur = 0
	for i in range(len(a1)):
		cur += a1[i]
		ans2 = max(ans2, cur - mn)
		mn = min(mn, cur)
	print(max(ans1, ans2, 0) + sm)


def lis(a, n):
	i = 0
	sum = 0
	max = 0
	k = -1
	j = [0, 0]
	while i < n:
		sum += a[i]
		if sum <= 0:
			k = i
			sum = 0
		if sum > max:
			j[0] = k + 2
			j[1] = i + 1
			max = sum
		i += 1
	return max
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a[::2])
	if n & 1:
		a.append(0)
		n += 1
	i = 0
	b = []
	while i < n:
		b.append(a[i + 1] - a[i])
		i += 2
	m = lis(b, len(b))
	i = 2
	b = []
	while i < n:
		b.append(a[i - 1] - a[i])
		i += 2
	n = lis(b, len(b))
	print(s + max(m, n))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(0, n, 2):
		ans += a[i]
	s = 0
	mx = 0
	for i in range(0, n - 1, 2):
		s += a[i + 1] - a[i]
		mx = max(s, mx)
		if s < 0:
			s = 0
	s = 0
	for i in range(1, n - 1, 2):
		s += a[i] - a[i + 1]
		mx = max(mx, s)
		if s < 0:
			s = 0
	print(ans + mx)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	sum = 0
	for i in range(0, n, 2):
		sum += a[i]
	mmax = 0
	cur = 0
	for i in range(1, n, 2):
		cur = max(0, a[i] - a[i - 1] + cur)
		mmax = max(mmax, cur)
	cur = 0
	for i in range(2, n, 2):
		cur = max(0, a[i - 1] - a[i] + cur)
		mmax = max(mmax, cur)
	sum += mmax
	print(sum)


for t in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	r = s = rs = 0
	x = n // 2
	for i in range(x):
		s = s + (lst[2 * i + 1] - lst[2 * i])
		rs = rs + lst[2 * i]
		s = max(s, 0)
		if s > r:
			r = s
	if n % 2:
		rs += lst[-1]
	s = 0
	y = (n + 1) // 2
	for i in range(1, y):
		s += lst[2 * i - 1] - lst[2 * i]
		s = max(s, 0)
		if s > r:
			r = s
	print(rs + r)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
	else:
		ans = 0
		for i in range(0, n, 2):
			ans += a[i]
		f = []
		s = []
		i = 1
		while i < n:
			f.append(a[i] - a[i - 1])
			if i + 1 < n:
				s.append(a[i] - a[i + 1])
			i += 2
		mx = f[0]
		sum = 0
		min_sum = 0
		for i in range(len(f)):
			sum += f[i]
			mx = max(mx, sum - min_sum)
			min_sum = min(min_sum, sum)
		sum = 0
		min_sum = 0
		for i in range(len(s)):
			sum += s[i]
			mx = max(mx, sum - min_sum)
			min_sum = min(min_sum, sum)
		if mx > 0:
			print(ans + mx)
		else:
			print(ans)


def solve(arr, n, ans):
	odd = 0
	even = 0
	dp = []
	even_indices = [(float('inf'), -1)]
	odd_indices = [(float('inf'), -1)]
	for i in range(n):
		if i % 2 == 0:
			even += arr[i]
		else:
			odd += arr[i]
		dp.append(odd - even)
		if i % 2 == 0:
			odd_indices.append(odd_indices[-1])
			if dp[-1] <= even_indices[-1][0]:
				even_indices.append((dp[-1], i))
			else:
				even_indices.append(even_indices[-1])
		else:
			even_indices.append(even_indices[-1])
			if dp[-1] <= odd_indices[-1][0]:
				odd_indices.append((dp[-1], i))
			else:
				odd_indices.append(odd_indices[-1])
	even_indices.pop(0)
	odd_indices.pop(0)
	max_val = 0
	l = -1
	r = -1
	for i in range(1, n):
		if i % 2 != 0:
			diff = dp[i] - odd_indices[i - 1][0]
			if diff > max_val:
				max_val = diff
				l = odd_indices[i - 1][1] + 1
				r = i
			if dp[i] > max_val:
				max_val = dp[i]
				l = 0
				r = i
		else:
			diff = dp[i] - even_indices[i - 1][0]
			if diff > max_val:
				max_val = diff
				l = even_indices[i - 1][1] + 1
				r = i
	if l != -1:
		reverse(arr, l, r, n)
	total = find(arr, n)
	ans.append(total)

def reverse(arr, l, r, n):
	for i in range((r - l + 1) // 2):
		(arr[l + i], arr[r - i]) = (arr[r - i], arr[l + i])

def find(arr, n):
	total = 0
	for i in range(n):
		if i % 2 == 0:
			total += arr[i]
	return total

def brute(arr, n, ans):
	ans = 0
	li = -1
	ri = -1
	for l in range(n):
		for r in range(l, n):
			reverse(arr, l, r, n)
			total = find(arr, n)
			if total > ans:
				ans = total
				li = l
				ri = r
			reverse(arr, l, r, n)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	for i in ans:
		print(i)
main()


q = int(input())
for i in range(q):
	n = int(input())
	lst = [int(x) for x in input().split()]
	if n == 1:
		print(lst[0])
		continue
	se = so = mx = mn = 0
	k = 1
	while k < n:
		if se >= 0:
			se += lst[k] - lst[k - 1]
		else:
			se = lst[k] - lst[k - 1]
		k += 2
		mx = max(mx, se)
	k = 2
	while k < n:
		if so <= 0:
			so += lst[k] - lst[k - 1]
		else:
			so = lst[k] - lst[k - 1]
		mn = min(mn, so)
		k += 2
	ret = 0
	k = 0
	mx = max(abs(mn), mx)
	while k < n:
		ret += lst[k]
		k += 2
	if mx > 0:
		print(ret + mx)
	else:
		print(ret)


import sys
input = sys.stdin.readline
cases = int(input())
for tt in range(cases):
	n = int(input())
	a = [int(x) for x in input().split()]
	prev = []
	next = []
	ans = 0
	mx = 0
	for i in range(0, len(a), 2):
		ans += a[i]
	for i in range(1, len(a), 2):
		prev.append(a[i] - a[i - 1])
		if i < len(a) - 1:
			next.append(a[i] - a[i + 1])
	max_sum = 0
	cur_sum = 0
	for i in range(len(next)):
		cur_sum += next[i]
		max_sum = max(cur_sum, max_sum)
		cur_sum = max(cur_sum, 0)
	cur_sum = 0
	mx_sum = 0
	for i in range(len(prev)):
		cur_sum += prev[i]
		mx_sum = max(cur_sum, mx_sum)
		cur_sum = max(cur_sum, 0)
	print(ans + max(mx_sum, max_sum))


t = int(input())

def func(pref):
	msum = float('inf')
	bsum = -float('inf')
	for p in pref:
		msum = min(p, msum)
		bsum = max(bsum, p - msum)
	return bsum
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	evsum = 0
	for i in range(0, (n + 1) // 2):
		evsum += a[2 * i]
	v1 = []
	v2 = []
	if n % 2 == 0:
		m1 = n // 2
		m2 = n // 2
	else:
		m1 = n // 2
		m2 = n // 2 + 1
	for i in range(0, m1):
		v1.append(a[2 * i + 1] - a[2 * i])
	for i in range(1, m2):
		v2.append(a[2 * i - 1] - a[2 * i])
	prefs1 = [0]
	prefs2 = [0]
	s1 = 0
	s2 = 0
	for i in range(len(v1)):
		s1 += v1[i]
		prefs1.append(s1)
	for i in range(len(v2)):
		s2 += v2[i]
		prefs2.append(s2)
	b1 = func(prefs1)
	b2 = func(prefs2)
	print(evsum + max(b1, b2))


from sys import stdout, stdin

def maxSubArraySum(a):
	size = len(a)
	if size == 0:
		return 0
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	ls = list(map(int, stdin.readline().split()))
	if n % 2 == 1:
		ls.append(0)
	n += 1
	sm = 0
	diff = []
	diff2 = []
	for i in range(0, n - 1, 2):
		sm += ls[i]
		diff.append(ls[i + 1] - ls[i])
	for i in range(1, n - 2, 2):
		diff2.append(ls[i] - ls[i + 1])
	a = maxSubArraySum(diff)
	b = maxSubArraySum(diff2)
	stdout.write(str(max(max(a, b), 0) + sm) + '\n')


def maxSubArraySum(a, size):
	max_so_far = -1000000000000000000
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
wqr = int(input())
for er in range(wqr):
	a = int(input())
	temp = list(map(int, input().split(' ')))
	temp1 = []
	ans = 0
	i = 0
	while i < a:
		ans += temp[i]
		i += 2
	i = 0
	while i < a - 1:
		temp1.append(temp[i + 1] - temp[i])
		i += 2
	t = maxSubArraySum(temp1, len(temp1))
	i = 1
	temp2 = []
	while i < a - 1:
		temp2.append(temp[i] - temp[i + 1])
		i += 2
	t1 = maxSubArraySum(temp2, len(temp2))
	m = max(t, t1)
	if m > 0:
		ans += m
	print(ans)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	num = 0
	parr = 0
	imparrr = 0
	n = int(sys.stdin.readline())
	a = list(map(int, input().split()))
	suma = 0
	for i in range(len(a)):
		if i % 2 == 0:
			suma += a[i]
	for i in range(0, n - 1, 2):
		num += a[i + 1] - a[i]
		parr = max(parr, num)
		if num < 0:
			num = 0
	num = 0
	for i in range(1, n - 1, 2):
		num += a[i] - a[i + 1]
		parr = max(parr, num)
		if num < 0:
			num = 0
	print(parr + suma)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	if n == 1:
		print(sum(A))
		continue
	sumA = 0
	for i in range(n):
		if i % 2 == 0:
			sumA += A[i]
	E = []
	for i in range(n):
		if i % 2 == 1:
			continue
		if i + 1 < n:
			E.append(A[i + 1] - A[i])
	O = []
	for i in range(1, n):
		if i % 2 == 0:
			continue
		if i + 1 < n:
			O.append(A[i] - A[i + 1])
	m = len(E)
	INF = 10 ** 18
	dpe = [-INF] * (m + 1)
	for i in range(m):
		dpe[i + 1] = max(E[i], dpe[i] + E[i])
	e = max(dpe)
	l = len(O)
	dpo = [-INF] * (l + 1)
	for i in range(l):
		dpo[i + 1] = max(O[i], dpo[i] + O[i])
	o = max(dpo)
	ans = sumA + max([o, e, 0])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	maxi = 0
	curr = 0
	for i in range(0, n - 1, 2):
		curr += arr[i + 1] - arr[i]
		curr = max(0, curr)
		maxi = max(curr, maxi)
	curr = 0
	for i in range(1, n - 1, 2):
		curr += arr[i] - arr[i + 1]
		curr = max(0, curr)
		maxi = max(curr, maxi)
	total = 0
	for i in range(0, n, 2):
		total += arr[i]
	print(total + maxi)


def kadane(arr):
	max_current = arr[0]
	max_global = arr[0]
	n = len(arr)
	for i in range(1, n):
		max_current = max(arr[i], max_current + arr[i])
		if max_current > max_global:
			max_global = max_current
	return max_global
t = int(input())
for tc in range(t):
	length = int(input())
	if length == 1:
		n = int(input())
		print(n)
		continue
	if length == 2:
		line = input().split()
		print(max(int(line[0]), int(line[1])))
		continue
	line = input().split()
	arr = []
	diff1 = []
	diff2 = []
	for x in line:
		arr.append(int(x))
	if length % 2 == 0:
		for x in range(0, length - 1, 2):
			diff1.append(arr[x + 1] - arr[x])
		for x in range(1, length - 2, 2):
			diff2.append(arr[x] - arr[x + 1])
	if length % 2 != 0:
		for x in range(0, length - 1, 2):
			diff1.append(arr[x + 1] - arr[x])
		for x in range(1, length - 1, 2):
			diff2.append(arr[x] - arr[x + 1])
	add_this = max(kadane(diff1), kadane(diff2))
	if add_this < 0:
		add_this = 0
	for x in range(0, length, 2):
		add_this += arr[x]
	print(add_this)


def maxSubArraySum(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_ending_here < 0:
			max_ending_here = 0
		elif max_so_far < max_ending_here:
			max_so_far = max_ending_here
	return max_so_far
for ad in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	diff = []
	ans = 0
	for i in range(0, n // 2 * 2, 2):
		diff.append(a[i + 1] - a[i])
	diff2 = []
	for i in range(1, (n - 1) // 2 * 2, 2):
		diff2.append(a[i] - a[i + 1])
	for i in range(0, n, 2):
		ans += a[i]
	x = maxSubArraySum(diff, len(diff))
	y = maxSubArraySum(diff2, len(diff2))
	ans += max(0, x, y)
	print(ans)


def getmax(nums):
	if len(nums) == 0:
		return (0, 0, 0)
	if len(nums) == 1:
		if nums[0] < 0:
			return (0, 0, 0)
		return (nums[0], 0, 0)
	meh = 0
	msf = 0
	start = 0
	end = 0
	s = 0
	for i in range(len(nums)):
		meh = meh + nums[i]
		if meh < 0:
			meh = 0
			s = i + 1
		if meh > msf:
			msf = meh
			start = s
			end = i
	return (msf, start, end)
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
	else:
		nums = []
		for i in range(0, n - 1, 2):
			nums.append(a[i + 1] - a[i])
		nums2 = []
		for i in range(1, n - 1, 2):
			nums2.append(a[i] - a[i + 1])
		(m1, s1, e1) = getmax(nums)
		(m2, s2, e2) = getmax(nums2)
		s1 = 2 * s1
		e1 = 2 * e1
		s2 = 1 + 2 * s2
		e2 = 1 + 2 * e2
		if m1 > m2:
			start = s1
			end = e1
		else:
			start = s2
			end = e2
		ans = 0
		for i in range(0, n, 2):
			ans += a[i]
		ans += max(m1, m2)
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	num_ini = 0
	for i in range(0, n, 2):
		num_ini += a[i]
	dif1 = []
	for i in range(0, n - 1, 2):
		dif1.append(a[i + 1] - a[i])
	dif2 = []
	for i in range(1, n - 1, 2):
		dif2.append(a[i] - a[i + 1])
	dp1 = [0] * (len(dif1) + 1)
	dp2 = [0] * (len(dif2) + 1)
	for i in range(1, len(dp1)):
		dp1[i] = max(dp1[i - 1] + dif1[i - 1], 0)
	for j in range(1, len(dp2)):
		dp2[j] = max(dp2[j - 1] + dif2[j - 1], 0)
	print(max(max(dp1), max(dp2)) + num_ini)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp0 = [[0, 0, 0] for i in range((n - 1) // 2 + 1)]
	for i in range((n - 1) // 2 + 1):
		if i == 0:
			dp0[i][0] = a[2 * i]
			continue
		dp0[i][0] = dp0[i - 1][0] + a[2 * i]
		dp0[i][1] = max(dp0[i - 1][0], dp0[i - 1][1]) + a[2 * i - 1]
		dp0[i][2] = max(dp0[i - 1][1], dp0[i - 1][2]) + a[2 * i]
	dp1 = [[0, 0, 0] for i in range((n - 1) // 2 + 1)]
	for i in range((n - 1) // 2 + 1):
		if i == 0:
			dp1[i][0] = a[2 * i]
			if 2 * i + 1 < n:
				dp1[i][1] = a[2 * i + 1]
			continue
		dp1[i][0] = dp1[i - 1][0] + a[2 * i]
		if 2 * i + 1 < n:
			dp1[i][1] = max(dp1[i - 1][0], dp1[i - 1][1]) + a[2 * i + 1]
		if 2 * i < n:
			dp1[i][2] = max(dp1[i - 1][1], dp1[i - 1][2]) + a[2 * i]
	print(max(dp0[(n - 1) // 2] + dp1[(n - 1) // 2]))


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def maxEvenLenSum(arr, n):
	if n < 2:
		return 0
	dp = [0 for i in range(n)]
	dp[n - 1] = 0
	dp[n - 2] = arr[n - 2] + arr[n - 1]
	for i in range(n - 3, -1, -1):
		dp[i] = arr[i] + arr[i + 1]
		if dp[i + 2] > 0:
			dp[i] += dp[i + 2]
	maxSum = max(dp)
	return maxSum

def solution(a, n):
	b = [a[i] if i % 2 else -a[i] for i in range(n)]
	return sum(a[::2]) + maxEvenLenSum(b, n)

def main():
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		x = solution(a, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


t = int(input())
for a in range(t):
	N = int(input())
	A = list(map(int, input().split()))
	k = 0
	for i in range(0, N, 2):
		k += A[i]
	S = 0
	x = 0
	for i in range(0, N - 1, 2):
		S += A[i + 1] - A[i]
		x = max(S, x)
		if S < 0:
			S = 0
	S = 0
	for i in range(1, N - 1, 2):
		S += A[i] - A[i + 1]
		x = max(x, S)
		if S < 0:
			S = 0
	print(k + x)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cur = a[0]
	curodd = 0
	cureven = 0
	maxalt = 0
	for i in range(1, n):
		if i % 2 == 1:
			curodd += a[i] - a[i - 1]
			maxalt = max(maxalt, curodd)
			if curodd < 0:
				curodd = 0
		else:
			cureven -= a[i] - a[i - 1]
			maxalt = max(maxalt, cureven)
			cur += a[i]
			if cureven < 0:
				cureven = 0
	print(cur + maxalt)


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))

def kadane(l):
	res = 0
	ans = 0
	for ll in l:
		if ll + res > 0:
			res = ll + res
			ans = max(ans, res)
		else:
			res = 0
	return ans

def solve():
	tt = I()
	for ii in range(tt):
		n = I()
		l = IL()
		ans = 0
		for i in range(len(l)):
			if i % 2 == 0:
				ans += l[i]
		x1 = [l[i] - l[i - 1] for i in range(1, len(l), 2)]
		x2 = [l[i - 1] - l[i] for i in range(2, len(l), 2)]
		a1 = kadane(x1)
		a2 = kadane(x2)
		a3 = max(a1, a2)
		ans += a3
		print(ans)
solve()


for lo in range(int(input())):
	n = int(input())
	ls = [int(x) for x in input().split()]
	mxd = 0
	currmxd = 0
	se = 0
	so = 0
	m = n
	if n % 2 != 0:
		m = n - 1
	for i in range(0, m, 2):
		so += ls[i + 1]
		se += ls[i]
		if so >= se:
			currmxd = so - se
			if mxd <= currmxd:
				mxd = currmxd
		else:
			so = 0
			se = 0
			currmxd = 0
	m = n
	if n % 2 == 0:
		m = n - 1
	se = 0
	so = 0
	currmxd = 0
	for i in range(1, m, 2):
		so += ls[i]
		se += ls[i + 1]
		if so >= se:
			currmxd = so - se
			if mxd <= currmxd:
				mxd = currmxd
		else:
			so = 0
			se = 0
			currmxd = 0
	res = 0
	for i in range(0, n, 2):
		res += ls[i]
	print(res + mxd)


def max_sub(a):
	total_max = 0
	cur_max = 0
	for v in a:
		cur_max += v
		cur_max = max(cur_max, 0)
		total_max = max(total_max, cur_max)
	return total_max
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a1 = list(a[::2])
	a2 = list(a[1::2])
	d1 = list((y - x for (x, y) in zip(a1, a2)))
	d2 = list((y - x for (x, y) in zip(a1[1:], a2)))
	print(sum(a1) + max(max_sub(d1), max_sub(d2)))


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			n = inp()
			a = inlt()
			dp = [[0, 0, 0] for i in range(n + 1)]
			for i in range(n):
				dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + (i % 2 == 0) * a[i])
				if i + 2 <= n:
					dp[i + 2][1] = max(dp[i + 2][1], max(dp[i][0], dp[i][1]) + (i % 2 == 0) * a[i + 1] + (not i % 2 == 0) * a[i])
				dp[i + 1][2] = max(dp[i + 1][2], max(dp[i]) + (i % 2 == 0) * a[i])
			print(max(dp[n]))
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(a) for a in input().split()]
	ans = 0
	num = 0
	m = 0
	for i in range(n):
		if i % 2 == 0:
			ans += A[i]
			num += A[i]
		else:
			num -= A[i]
			num = min(0, num)
			m = min(m, num)
	num = 0
	for i in range(1, n):
		if i % 2 == 0:
			num += A[i]
			num = min(0, num)
			m = min(m, num)
		else:
			num -= A[i]
	print(ans - m)


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(itg()):
	n = itg()
	arr = tuple(mpint())
	ans = sum(arr[::2])
	c1 = c2 = 0
	c = 0
	for i in range(0, n - 1, 2):
		c1 = max(c1, c)
		c += arr[i + 1] - arr[i]
		if c < 0:
			c = 0
	c1 = max(c1, c)
	c = 0
	for i in range(1, n - 1, 2):
		c2 = max(c2, c)
		c += arr[i] - arr[i + 1]
		if c < 0:
			c = 0
	c2 = max(c2, c)
	ans += max(c1, c2)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd = [0] * n
	even = [0] * n
	for i in range(n):
		if i % 2 == 0:
			odd[i] = odd[i - 1]
			even[i] = even[i - 1] + a[i]
		else:
			odd[i] = odd[i - 1] + a[i]
			even[i] = even[i - 1]
	ODD = [odd[i] - even[i] for i in range(n) if i % 2 == 1]
	EVEN = [odd[i] - even[i] for i in range(n) if i % 2 == 0]
	for i in range(len(ODD) - 2, -1, -1):
		ODD[i] = max(ODD[i], ODD[i + 1])
	for i in range(len(EVEN) - 2, -1, -1):
		EVEN[i] = max(EVEN[i], EVEN[i + 1])
	ans = -float('inf')
	for i in range(n - 1):
		if i != 0:
			test = even[i - 1] - odd[i - 1]
		else:
			test = 0
		if i % 2 == 0:
			k = i // 2
			test += ODD[k]
		else:
			k = i // 2
			test += EVEN[k + 1]
		ans = max(ans, test)
	S = sum((a[i] for i in range(n) if i % 2 == 0))
	print(max(S, S + ans))


from sys import stdin
input = stdin.readline

def answer():
	dp = [[0, 0, 0, 0] for i in range(n + 1)]
	for i in range(1, n + 1):
		dp[i][0] = dp[i - 1][0]
		dp[i][1] = dp[i - 1][1]
		dp[i][2] = dp[i - 1][2]
		dp[i][3] = dp[i - 1][3]
		if i & 1:
			dp[i][0] += a[i - 1]
			dp[i][3] += a[i - 1]
			dp[i][1] = max(dp[i][1], dp[i - 1][0])
			dp[i][3] = max(dp[i][3], dp[i][2], dp[i][0])
		else:
			dp[i][1] += a[i - 1]
			dp[i][2] = max(dp[i][2], dp[i - 1][0]) + a[i - 1]
			dp[i][3] = max(dp[i][3], dp[i][1])
	return dp[n][3]
for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(answer())


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = tuple(map(int, input().split()))
		m = 0
		c = 0
		start = None
		curr_start = None
		end = None
		for i in range(0, n, 2):
			if n - i < 2:
				break
			d = a[i] - a[i + 1]
			if c + d <= 0:
				if c >= 0:
					curr_start = i
				c += d
			else:
				c = 0
			if c < m:
				m = c
				start = curr_start
				end = i + 1
		cc = 0
		curr_start = None
		for i in range(1, n, 2):
			if n - i < 2:
				break
			d = a[i + 1] - a[i]
			if cc + d <= 0:
				if cc >= 0:
					curr_start = i
				cc += d
			else:
				cc = 0
			if cc < m:
				m = cc
				start = curr_start
				end = i + 1
		result = 0
		for i in range(n):
			if start is None or end is None:
				if i % 2 == 0:
					result += a[i]
				continue
			if (i < start or i > end) and i % 2 == 1:
				continue
			if start <= i <= end and i % 2 == 0:
				continue
			result += a[i]
		print(result)
main()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		n = ri()
		a = ria()
		s = 0
		for i in range(n):
			if i % 2 == 0:
				s += a[i]
		mx_sum = 0
		cur_sum = 0
		for i in range(0, n, 2):
			if i + 1 >= n:
				break
			cur_sum = max(0, cur_sum + a[i + 1] - a[i])
			mx_sum = max(mx_sum, cur_sum)
		cur_sum = 0
		for i in range(1, n, 2):
			if i + 1 >= n:
				break
			cur_sum = max(0, cur_sum + a[i] - a[i + 1])
			mx_sum = max(mx_sum, cur_sum)
		print(s + mx_sum)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	n1 = []
	n2 = []
	v = 1
	res = 0
	while v < n:
		n1.append(a[v] - a[v - 1])
		v = v + 2
	v = 2
	while v < n:
		res = res + a[v - 2]
		n2.append(-a[v] + a[v - 1])
		v = v + 2
	res = res + a[v - 2]
	b1 = 0
	max1 = 0
	for h in range(len(n1)):
		b1 = b1 + n1[h]
		if b1 < 0:
			b1 = 0
		if max1 < b1:
			max1 = b1
	b1 = 0
	for h in range(len(n2)):
		b1 = b1 + n2[h]
		if b1 < 0:
			b1 = 0
		if max1 < b1:
			max1 = b1
	print(res + max1)


def msa(a):
	if a == []:
		return 0
	(ans, cur) = (0, 0)
	for x in a:
		if x < 0:
			ans = max(ans, cur)
		cur += x
		if cur < 0:
			ans = max(ans, cur - x)
			cur = 0
	ans = max(cur, ans)
	return ans if ans > 0 else max(a)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(a1, a2) = ([], [])
	initsum = 0
	for i in range(0, n, 2):
		initsum += a[i]
		if i + 1 >= n:
			break
		a1.append(a[i + 1] - a[i])
	for i in range(1, n, 2):
		if i + 1 >= n:
			break
		a2.append(a[i] - a[i + 1])
	addition = max(msa(a1), msa(a2))
	print(initsum + (addition if addition > 0 else 0))


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
INF = 10 ** 10

def calc(T):
	N = len(T)
	Tm = [-INF] * N
	Tm[N - 1] = T[N - 1]
	for i in reversed(range(N - 1)):
		Tm[i] = max(Tm[i + 1], T[i])
	return max((Tm[i] - T[i] for i in range(N)))

def solve(N, A):
	S0 = [0]
	S1 = [0]
	for i in range(N):
		if i % 2 == 0:
			S0.append(S0[-1] + A[i])
			S1.append(S1[-1])
		else:
			S0.append(S0[-1])
			S1.append(S1[-1] + A[i])
	T = [S1[i] - S0[i] for i in range(N + 1)]
	T0 = T[0::2]
	T1 = T[1::2]
	v = max(calc(T0), calc(T1))
	return S0[N] + v
T0 = int(input())
for _ in range(T0):
	N = int(input())
	A = list(map(int, input().split()))
	print(solve(N, A))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(var) for var in input().split()]
	if n < 3:
		print(max(arr))
	else:
		(arr1, arr2) = ([], [])
		for oddIdx in range(1, n, 2):
			arr1.append(arr[oddIdx] - arr[oddIdx - 1])
		for evenIdx in range(2, n, 2):
			arr2.append(arr[evenIdx - 1] - arr[evenIdx])
		total = sum((arr[x] for x in range(0, n, 2)))
		(maxSubArray1, maxSubArray2) = ([0 for _ in range(len(arr1))], [0 for _ in range(len(arr2))])
		(maxSubArray1[0], maxSubArray2[0]) = (max(0, arr1[0]), max(0, arr2[0]))
		for i in range(1, len(arr1)):
			maxSubArray1[i] = max(maxSubArray1[i - 1] + arr1[i], arr1[i], 0)
		for i in range(1, len(arr2)):
			maxSubArray2[i] = max(maxSubArray2[i - 1] + arr2[i], arr2[i], 0)
		print(total + max(max(maxSubArray2), max(maxSubArray1)))


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['NET', 'DA']
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	a = li()
	s = sum([a[i] for i in range(0, n, 2)])
	s1 = s2 = mx1 = mx2 = 0
	for i in range(1, n, 2):
		x = a[i] - a[i - 1]
		if s1 + x > 0:
			s1 += x
			mx1 = max(mx1, s1)
		else:
			s1 = 0
	for i in range(2, n, 2):
		y = a[i - 1] - a[i]
		if s2 + y > 0:
			s2 += y
			mx2 = max(mx2, s2)
		else:
			s2 = 0
	print(s + max(mx1, mx2))


t = int(input())
for p in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	for i in range(0, n, 2):
		cnt += a[i]
	sum1 = 0
	maxim1 = 0
	for i in range(0, n - 1, 2):
		sum1 = max(a[i + 1] - a[i] + sum1, a[i + 1] - a[i])
		maxim1 = max(maxim1, sum1)
	sum2 = 0
	maxim2 = 0
	for i in range(1, n - 1, 2):
		sum2 = max(a[i] - a[i + 1] + sum2, a[i] - a[i + 1])
		maxim2 = max(maxim2, sum2)
	print(max(maxim1, maxim2) + cnt)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	n1 = []
	n2 = []
	for i in range(0, n - 1, 2):
		n1.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		n2.append(a[i] - a[i + 1])
	ans = 0
	dopans = 0
	for i in range(n):
		if i % 2:
			pass
		else:
			dopans += a[i]
	if len(n1):
		dp1 = [0 for i in range(len(n1))]
		dp1[0] = max(n1[0], 0)
		for i in range(1, len(n1)):
			dp1[i] = max(0, dp1[i - 1] + n1[i])
	else:
		dp1 = [0]
	if len(n2):
		dp2 = [0 for i in range(len(n2))]
		dp2[0] = max(n2[0], 0)
		for i in range(1, len(n2)):
			dp2[i] = max(0, dp2[i - 1] + n2[i])
	else:
		dp2 = [0]
	print(dopans + max(max(dp1), max(dp2)))
for i in range(int(input())):
	solve()


from collections import defaultdict
for i in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	eo = [[0, 0]]
	even = 0
	odd = 0
	mn_o = [10 ** 9 + 1]
	mn_e = [10 ** 9 + 1]
	for i in range(len(arr)):
		if i % 2 == 0:
			even += arr[i]
		else:
			odd += arr[i]
		eo.append([even, odd])
	for i in range(len(eo)):
		if i % 2 == 0:
			mn_e.append(min(mn_e[-1], eo[i][1] - eo[i][0]))
			mn_o.append(mn_o[-1])
		else:
			mn_o.append(min(mn_o[-1], eo[i][1] - eo[i][0]))
			mn_e.append(mn_e[-1])
	ans = 0
	for i in range(1, len(eo), 2):
		ans = max(ans, eo[i][1] - eo[i][0] - mn_o[i])
	for i in range(0, len(eo), 2):
		ans = max(ans, eo[i][1] - eo[i][0] - mn_e[i])
	print(ans + eo[-1][0])


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [int(x) for x in input().split()]
		B = []
		C = []
		s = 0
		for i in range(0, N, 2):
			s += A[i]
			if i != N - 1:
				B.append(A[i + 1] - A[i])
			if i != 0:
				C.append(A[i - 1] - A[i])
		ma = 0
		r = 0
		tmp = 0
		for l in range(len(B)):
			while r < len(B) and tmp >= 0:
				tmp += B[r]
				ma = max(ma, tmp)
				r += 1
			tmp -= B[l]
		r = 0
		tmp = 0
		for l in range(len(C)):
			while r < len(C) and tmp >= 0:
				tmp += C[r]
				ma = max(ma, tmp)
				r += 1
			tmp -= C[l]
		print(s + ma)
main()


n = input()
for i in range(int(n)):
	n_i = input()
	numbers = list(map(int, input().split(' ')))
	a = numbers[1::2]
	b = numbers[:-1:2]
	before = [i - j for (i, j) in zip(a, b)]
	a = numbers[1:-1][::2]
	b = numbers[2:][::2]
	after = [i - j for (i, j) in zip(a, b)]
	start = sum(numbers[::2])
	max_ = 0
	for diffs in [before, after]:
		csum = 0
		msum = 0
		for i in range(len(diffs)):
			csum = csum + diffs[i]
			msum = min(msum, csum)
			d = csum - msum
			if d > max_:
				max_ = d
	print(start + max_)


def maximum_sum_subarray(arr):
	length = len(arr)
	temp = [0] * length
	if length == 0:
		return 0
	if length == 1:
		return max(arr[0], 0)
	temp[0] = max(arr[0], 0)
	_max = temp[0]
	for i in range(1, len(arr)):
		temp[i] = max(0, temp[i - 1] + arr[i])
		if temp[i] > _max:
			_max = temp[i]
	return _max
t = int(input())
for case in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	arr1 = []
	arr2 = []
	_sum = arr[0]
	for i in range(1, len(arr)):
		if i % 2 == 1:
			arr1.append(arr[i] - arr[i - 1])
		else:
			arr2.append(arr[i - 1] - arr[i])
			_sum += arr[i]
	_max1 = maximum_sum_subarray(arr1)
	_max2 = maximum_sum_subarray(arr2)
	print(_sum + max(_max1, _max2))


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if n == 1:
		print(lis[0])
	elif n == 2:
		print(max(lis))
	else:
		dif1 = []
		dif2 = []
		tit = 0
		for i in range(len(lis)):
			if i % 2 == 0:
				tit += lis[i]
		i = 0
		while i < len(lis) - 1:
			dif1.append(lis[i + 1] - lis[i])
			i += 2
		j = 1
		while j < len(lis) - 1:
			dif2.append(-1 * (lis[j + 1] - lis[j]))
			j += 2

		def kadane(lis):
			tolmax = -1 * float('inf')
			locmax = 0
			for i in range(len(lis)):
				locmax = max(lis[i], locmax + lis[i])
				if locmax > tolmax:
					tolmax = locmax
			return tolmax
		a = max(kadane(dif1), kadane(dif2))
		if a > 0:
			print(tit + a)
		else:
			print(tit)


import math

def maxSubArraySum(a, size):
	max_so_far = -math.inf - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	si = 0
	for i in range(len(a)):
		if i % 2 == 0:
			si += a[i]
	su = [si]
	b = []
	for i in range(0, len(a) - 1, 2):
		b.append(-a[i] + a[i + 1])
	c = maxSubArraySum(b, len(b))
	su.append(si + c)
	b = []
	for i in range(1, len(a) - 1, 2):
		b.append(+a[i] - a[i + 1])
	c = maxSubArraySum(b, len(b))
	su.append(si + c)
	print(max(su))


import sys
from collections import Counter as cc, defaultdict as df
from math import *

def counter(l):
	return dict(cc(l))
bin = lambda x: format(x, 'b')

def ini():
	return int(sys.stdin.readline())

def inp():
	return map(int, sys.stdin.readline().strip().split())

def li():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()

def inputm(n, m):
	return [li() for i in range(m)]
for i in range(ini()):
	n = ini()
	l = li()
	c = 0
	m = 0
	for i in range(0, n - 1, 2):
		c += l[i + 1] - l[i]
		c = max(0, c)
		m = max(c, m)
	c = 0
	for i in range(1, n - 1, 2):
		c += l[i] - l[i + 1]
		c = max(0, c)
		m = max(c, m)
	s = 0
	for i in range(0, n, 2):
		s += l[i]
	print(s + m)


from random import randint
from collections import defaultdict
it = lambda : list(map(int, input().strip().split()))
INF = float('inf')

def solve():
	N = int(input())
	A = it()
	ans = 0
	mni = 0
	cur = 0
	for i in range(0, N - 1, 2):
		cur += A[i + 1] - A[i]
		ans = max(ans, cur - mni)
		mni = min(mni, cur)
	mni = 0
	cur = 0
	for i in range(1, N - 1, 2):
		cur += A[i] - A[i + 1]
		ans = max(ans, cur - mni)
		mni = min(mni, cur)
	return sum((A[i] for i in range(0, N, 2))) + max(0, ans)
T = int(input())
for _ in range(T):
	print(solve())


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ans = 0
	for i in range(N):
		if i % 2 == 0:
			ans += A[i]
	Max = 0
	prof = 0
	for i in range(0, N + 1, 2):
		if i + 1 >= N:
			break
		prof += A[i + 1] - A[i]
		if prof < 0:
			prof = 0
		Max = max(Max, prof)
	prof = 0
	for i in range(1, N + 1, 2):
		if i + 1 >= N:
			break
		prof += A[i] - A[i + 1]
		if prof < 0:
			prof = 0
		Max = max(Max, prof)
	print(ans + Max)


for it in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		if i % 2 == 0:
			sum += A[i]
	B = []
	C = []
	for i in range(0, n - 1, 2):
		B.append(A[i + 1] - A[i])
	for i in range(2, n, 2):
		C.append(A[i - 1] - A[i])
	r1 = -1 * 1000000007
	r2 = -1 * 1000000007
	sum1 = 0
	sum2 = 0
	for i in range(len(B)):
		sum1 += B[i]
		r1 = max(r1, sum1)
		if sum1 < 0:
			sum1 = 0
	for i in range(len(C)):
		sum2 += C[i]
		r2 = max(r2, sum2)
		if sum2 < 0:
			sum2 = 0
	sum += max(0, r1, r2)
	print(sum)


import sys

def solve(arr):
	if len(arr) <= 1:
		return 0 if len(arr) == 0 else arr[0]
	max_sum = 0
	l = len(arr)
	evens = arr[0::2]
	odds = arr[1::2]
	if l % 2 == 1:
		odds.append(0)
	hl = len(evens)
	even_cum = [arr[0]] * hl
	odd_cum = [arr[1]] * hl
	for ei in range(1, hl):
		even_cum[ei] = evens[ei] + even_cum[ei - 1]
	for oi in range(1, hl):
		odd_cum[oi] = odds[oi] + odd_cum[oi - 1]
	diff_r = [odds[i] - evens[i] for i in range(hl)]
	diff_l = [odds[i] - evens[i + 1] for i in range(hl - 1)]

	def largest_contig_sum(A):
		n = len(A)
		cum_sum = [0] * (n + 1)
		big_diff = 0
		mn = 0
		for i in range(1, n + 1):
			cum_sum[i] = cum_sum[i - 1] + A[i - 1]
			if cum_sum[i] < mn:
				mn = cum_sum[i]
			elif cum_sum[i] - mn > big_diff:
				big_diff = cum_sum[i] - mn
		return big_diff
	return sum(evens) + max(largest_contig_sum(diff_r), largest_contig_sum(diff_l))
	start = even_cum[-1]
	biggest_diff = 0
	for e1 in range(hl):
		for e2 in range(e1, hl):
			if e1 == 0:
				etot = even_cum[e2]
				otot1 = odd_cum[e2]
				if otot1 - etot > biggest_diff:
					biggest_diff = otot1 - etot
			else:
				etot = even_cum[e2] - even_cum[e1 - 1]
				otot1 = odd_cum[e2] - odd_cum[e1 - 1]
				if e1 == 1:
					otot2 = odd_cum[e2 - 1]
				else:
					otot2 = odd_cum[e2 - 1] - odd_cum[e1 - 2]
				biggest_diff = max(biggest_diff, otot1 - etot, otot2 - etot)
	return start + biggest_diff
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
for ti in range(T):
	arr = [int(x) for x in IN[2 + 2 * ti].split(' ')]
	max_sum = solve(arr)
	print(max_sum)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(0, n, 2):
		s += a[i]
	cur = 0
	ans = s
	for i in range(0, n, 2):
		if i + 1 >= n:
			break
		cur += a[i + 1] - a[i]
		cur = max(cur, 0)
		ans = max(ans, s + cur)
	cur = 0
	for i in range(1, n, 2):
		if i + 1 >= n:
			break
		cur += a[i] - a[i + 1]
		cur = max(cur, 0)
		ans = max(ans, s + cur)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	eveSum = 0
	for i in range(n):
		if i % 2 == 0:
			eveSum += arr[i]
	preSum = 0
	maxDiffSum = 0
	for i in range(1, n, 2):
		preSum = max(preSum + arr[i] - arr[i - 1], 0)
		maxDiffSum = max(maxDiffSum, preSum)
	preSum = 0
	for i in range(1, n - 1, 2):
		preSum = max(preSum + arr[i] - arr[i + 1], 0)
		maxDiffSum = max(maxDiffSum, preSum)
	print(eveSum + maxDiffSum)


from sys import stdin
input = stdin.readline
t = int(input())
ans = []

def kadane(r):
	(sum_here, sum_max) = (0, 0)
	for i in r:
		sum_here = max(i, i + sum_here)
		sum_max = max(sum_max, sum_here)
	return sum_max
for _ in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	if n % 2:
		l.append(0)
	sum = 0
	(p, q) = ([], [])
	for i in range(0, n, 2):
		sum += l[i]
		p.append(l[i + 1] - l[i])
	for i in range(1, n - 1, 2):
		q.append(l[i] - l[i + 1])
	ans.append(max(kadane(p), kadane(q)) + sum)
print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = 0
	for i in range(n):
		if i % 2 == 0:
			s += arr[i]
	a = []
	b = []
	for i in range(1, n):
		if i % 2 == 1:
			a.append(arr[i] - arr[i - 1])
	for i in range(1, n - 1):
		if i % 2 == 1:
			b.append(arr[i] - arr[i + 1])
	dp1 = [0]
	dp2 = [0]
	for i in range(len(a)):
		dp1.append(max(a[i], dp1[-1] + a[i]))
	for i in range(len(b)):
		dp2.append(max(b[i], dp2[-1] + b[i]))
	print(s + max(max(dp1), max(dp2)))


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	res = 0
	max_so_far_before = 0
	max_ending_before = 0
	max_so_far_after = 0
	max_ending_after = 0
	for (i, v) in enumerate(a):
		if i % 2 == 0:
			res += v
		else:
			max_ending_before += v - a[i - 1]
			if max_ending_before < 0:
				max_ending_before = 0
			if max_so_far_before < max_ending_before:
				max_so_far_before = max_ending_before
			if i < n - 1:
				max_ending_after += v - a[i + 1]
				if max_ending_after < 0:
					max_ending_after = 0
				if max_so_far_after < max_ending_after:
					max_so_far_after = max_ending_after
	res += max(max_so_far_after, max_so_far_before)
	print(res)


from sys import stdin, stdout
import math

def maxSubArraySum(a):
	size = len(a)
	max_so_far = -float('inf')
	max_ending_here = 0
	(start, end) = (0, float('inf'))
	tmp_start = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = tmp_start
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			tmp_start = i + 1
	return (max_so_far, start, end)
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ans = sum((a[i] for i in range(0, n, 2)))
	l = [a[i + 1] - a[i] for i in range(0, n - 1, 2)]
	(msum1, st, end) = maxSubArraySum(l)
	l = [a[i] - a[i + 1] for i in range(1, n - 1, 2)]
	(msum2, st, end) = maxSubArraySum(l)
	print(ans + max(0, msum1, msum2))


for cases in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	max1 = 0
	curr = 0
	for i in range(0, n - 1, 2):
		curr += l[i + 1] - l[i]
		if curr > 0:
			max1 = max(curr, max1)
		else:
			curr = 0
	curr = 0
	for i in range(1, n - 1, 2):
		curr += l[i] - l[i + 1]
		if curr > 0:
			max1 = max(curr, max1)
		else:
			curr = 0
	sum1 = 0
	for i in range(0, n, 2):
		sum1 += l[i]
	print(sum1 + max1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	odd = []
	even = []
	for i in range(n):
		if i % 2 == 0:
			even += [a[i]]
		else:
			odd += [a[i]]
	s = 0
	ans = 0
	for i in range(min(len(odd), len(even))):
		s = max(odd[i] - even[i], s + odd[i] - even[i])
		ans = max(ans, s)
	s = 0
	x = even[0]
	even.pop(0)
	for i in range(min(len(odd), len(even))):
		s = max(odd[i] - even[i], s + odd[i] - even[i])
		ans = max(ans, s)
	print(ans + sum(even) + x)


def ms(l):
	m = 0
	i = 0
	s = 0
	while i < len(l):
		s += l[i]
		m = max(s, m)
		if s < 0:
			s = 0
		i += 1
	return m

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	z = []
	for i in range(0, n - 1, 2):
		z.append(l[i + 1] - l[i])
	o = []
	for i in range(1, n - 1, 2):
		o.append(l[i] - l[i + 1])
	s = 0
	for i in range(0, n, 2):
		s += l[i]
	print(max(ms(o), ms(z)) + s)
t = int(input())
for _ in range(t):
	solve()


def msas(a):
	max_so_far = -float('inf') - 1
	max_ending_here = 0
	for i in range(0, len(a)):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
for _ in range(t):
	size = int(input())
	arr = [int(i) for i in input().split()]
	s = sum([arr[i] for i in range(0, len(arr), 2)])
	ar = arr + [0] * (len(arr) % 2)
	a = [ar[i + 1] - ar[i] for i in range(0, len(ar), 2)]
	br = arr[1:-1] if len(arr) % 2 == 0 else arr[1:]
	b = [br[i] - br[i + 1] for i in range(0, len(br), 2)]
	print(max(s + msas(a), s, s + msas(b)))


cases = int(input())
for i in range(cases):
	n = int(input())
	l2 = input().split(' ')
	arr = []
	sum1 = 0
	for a in l2:
		arr.append(int(a))
	diff1 = []
	for j in range(0, len(arr), 2):
		if j + 1 >= len(arr):
			break
		ele1 = arr[j]
		ele2 = arr[j + 1]
		diff1.append(ele2 - ele1)
	diff2 = []
	for k in range(1, len(arr), 2):
		if k + 1 >= len(arr):
			break
		ele1 = arr[k]
		ele2 = arr[k + 1]
		diff2.append(ele1 - ele2)
	for p in range(len(arr)):
		if p % 2 == 0:
			sum1 += arr[p]
	s1 = s2 = -1
	for a in range(len(diff1)):
		start = diff1[a]
		if start > 0:
			s1 = a
			break
	for b in range(len(diff2)):
		start = diff2[b]
		if start > 0:
			s2 = b
			break
	e1 = e2 = -1
	for c in range(len(diff1) - 1, -1, -1):
		end = diff1[c]
		if end > 0:
			e1 = c
			break
	for d in range(len(diff2) - 1, -1, -1):
		end = diff2[d]
		if end > 0:
			e2 = d
			break
	if s1 == e1 == s2 == e2 == -1:
		print(sum1)
		continue
	sum2 = sum3 = 0
	t1 = t2 = 0
	if e1 >= s1 and e1 != -1:
		for w in range(s1, e1 + 1):
			num = diff1[w]
			sum2 += num
			if sum2 > t1:
				t1 = sum2
			if sum2 < 0:
				sum2 = 0
	if e2 >= s2 and e2 != -1:
		for x in range(s2, e2 + 1):
			num = diff2[x]
			sum3 += num
			if sum3 > t2:
				t2 = sum3
			if sum3 < 0:
				sum3 = 0
	m = max(t1, t2)
	print(sum1 + m)


t = int(input())
oo = 10 ** 18
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sol = 0
	best = ce = co = 0
	loe = loo = 0
	for i in range(n):
		if i % 2 == 0:
			sol += a[i]
			ce += a[i]
			co -= a[i]
			best = max(best, -(ce - loe))
			loe = max(loe, ce)
		else:
			ce -= a[i]
			co += a[i]
			best = max(best, co - loo)
			loo = min(loo, co)
	print(sol + best)


from sys import stdin
input = stdin.readline
q = int(input())

def bestdif(tab):
	k = len(tab)
	best = 0
	mini = tab[0]
	for i in range(1, k):
		best = max(best, tab[i] - mini)
		mini = min(tab[i], mini)
	return best
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	parpref = [0] * (n + 1)
	nparpref = [0] * (n + 1)
	for i in range(1, n + 1):
		if i % 2 == 1:
			nparpref[i] = nparpref[i - 1] + l[i - 1]
		else:
			nparpref[i] = nparpref[i - 1]
		if i % 2 == 0:
			parpref[i] = parpref[i - 1] + l[i - 1]
		else:
			parpref[i] = parpref[i - 1]
	diff = [-nparpref[i] + parpref[i] for i in range(n + 1)]
	diffev = [diff[2 * i] for i in range((n + 2) // 2)]
	diffodd = [diff[2 * i + 1] for i in range((n + 1) // 2)]
	cykev = bestdif(diffev)
	cykodd = bestdif(diffodd)
	pocz = 0
	for i in range(n):
		if i % 2 == 0:
			pocz += l[i]
	print(pocz + max(cykev, cykodd))


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		elif input_format == 6:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enum = enumerate

def kad(r):
	m = 0
	e = 0
	l = 0
	lf = 0
	rf = -1
	for (d, (i, j)) in enum(r):
		e += j - i
		if e > m:
			m = e
			rf = d
			lf = l
		if e < 0:
			e = 0
			l = d
	log(m)
	return m

def solve():
	n = input(11)
	a = input(1)
	r1 = zip(a[::2], a[1::2])
	r2 = zip(a[2::2], a[1::2])
	o = sum(a[::2])
	log('o', o)
	k1 = kad(r1)
	k2 = kad(r2)
	k = max(k1, k2)
	out(o + k)
	return
for i in range(input(11)):
	solve()


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

def In():
	return map(int, sys.stdin.readline().split())

def Sn():
	return sys.stdin.readline().strip()

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		dp = [[0] * (n + 3) for i in range(3)]
		for i in range(n):
			dp[0][i + 1] = max(dp[0][i + 1], dp[0][i] + (0 if i & 1 else l[i]))
			if i + 2 <= n:
				dp[1][i + 2] = max(dp[1][i + 2], max(dp[0][i], dp[1][i]) + (l[i] if i & 1 else l[i + 1]))
			dp[2][i + 1] = max(dp[2][i + 1], max(dp[0][i], dp[1][i], dp[2][i]) + (0 if i & 1 else l[i]))
		print(max(dp[0][n], dp[1][n], dp[2][n]))
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	b = []
	ans = 0
	for i in range(0, n - 1, 2):
		b.append(a[i + 1] - a[i])
	for i in range(n):
		if i % 2 == 0:
			ans += a[i]
	d = []
	for i in range(1, n - 1, 2):
		d.append(a[i] - a[i + 1])
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, len(b)):
		max_ending_here = max_ending_here + b[i]
		if max_ending_here < 0:
			max_ending_here = 0
		elif max_so_far < max_ending_here:
			max_so_far = max_ending_here
	max_so_far1 = 0
	max_ending_here1 = 0
	for i in range(0, len(d)):
		max_ending_here1 = max_ending_here1 + d[i]
		if max_ending_here1 < 0:
			max_ending_here1 = 0
		elif max_so_far1 < max_ending_here1:
			max_so_far1 = max_ending_here1
	tmp = max(0, max_so_far, max_so_far1)
	print(ans + tmp)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0]
	psb = []
	c = [0]
	psc = []
	tota = 0
	for i in range(n):
		if i % 2 == 0:
			tota += a[i]
	for i in range(n):
		if i % 2 == 0 and i + 1 <= n - 1:
			b.append(a[i + 1] - a[i])
	for i in range(n):
		if i % 2 == 1 and i < n - 1:
			c.append(a[i] - a[i + 1])
	psb.append(b[0])
	psc.append(c[0])
	for i in range(1, len(b)):
		if psb[i - 1] + b[i] >= 0:
			psb.append(psb[i - 1] + b[i])
		else:
			psb.append(0)
	for i in range(1, len(c)):
		if psc[i - 1] + c[i] >= 0:
			psc.append(psc[i - 1] + c[i])
		else:
			psc.append(0)
	x = max(psb)
	y = max(psc)
	z = max(x, y)
	if z > 0:
		ans = tota + z
	else:
		ans = tota
	print(ans)


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
	os.write(1, '\n'.encode())
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
			else:
				stack.pop()
				if not stack:
					break
				to = stack[-1].send(to)
		return to
	return wrapped_func
T = read_i()
while T:
	T -= 1
	n = read_i()
	a = [read_i() for i in range(n)]
	init = sum(a[::2])
	(odd, even) = (0, 0)
	(min_odd, min_even) = (0, 0)
	ans = init
	for (i, v) in enumerate(a):
		if i % 2:
			odd += v
			cur = odd - even
			ans = max(ans, init + cur - min_odd)
			min_odd = min(min_odd, cur)
		else:
			even += v
			cur = odd - even + a[0]
			ans = max(ans, init + cur - min_even)
			min_even = min(min_even, cur)
	write_i(ans)
print_ans()


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	n = iinput()
	a = rlinput()
	a.insert(0, 0)
	oddpref = [0]
	evenpref = [0]
	for i in range(1, n + 1):
		if i % 2:
			oddpref.append(oddpref[-1] + a[i])
			evenpref.append(evenpref[-1])
		else:
			evenpref.append(evenpref[-1] + a[i])
			oddpref.append(oddpref[-1])
	leven = 0
	lodd = 0
	possible = [0]
	ans = 0
	for i in range(1, n + 1):
		if i % 2:
			oddval = oddpref[i] - oddpref[lodd]
			evenval = evenpref[i] - evenpref[lodd]
			if evenval > oddval:
				possible.append(evenval - oddval)
			else:
				lodd = i
			ans += a[i]
		else:
			evenval = evenpref[i] - evenpref[leven]
			oddval = oddpref[i] - oddpref[leven]
			if evenval > oddval:
				possible.append(evenval - oddval)
			else:
				leven = i
	print(ans + max(possible))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = total_even = sum(a[::2])
	min_diff = diff = 0
	for i in range(0, n - 1, 2):
		diff += a[i + 1] - a[i]
		ans = max(ans, total_even + diff - min_diff)
		min_diff = min(min_diff, diff)
	min_diff = diff = 0
	for i in range(1, n - 1, 2):
		diff += a[i] - a[i + 1]
		ans = max(ans, total_even + diff - min_diff)
		min_diff = min(min_diff, diff)
	print(ans)


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		ecnt = 0
		for i in range(0, n, 2):
			ecnt += l[i]
		pre1 = [0] * n
		pre2 = [0] * n
		for i in range(1, n, 2):
			pre1[i] = l[i] - l[i - 1]
			if i < n - 1:
				pre2[i] = l[i] - l[i + 1]
		pre1x = pre2x = pre1y = pre2y = 0
		for i in range(n):
			pre1x += pre1[i]
			pre2x += pre2[i]
			if pre1x < 0:
				pre1x = 0
			if pre2x < 0:
				pre2x = 0
			if pre1x > pre1y:
				pre1y = pre1x
			if pre2x > pre2y:
				pre2y = pre2x
		print(ecnt + max(0, pre1y, pre2y))
solution()


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
import collections as col
import math

def solve():
	N = getInt()
	A = getInts()
	if N == 1:
		return A[0]
	if N == 2:
		return max(A[0], A[1])
	D = []
	E = []
	evens = sum([A[j] for j in range(0, N, 2)])
	for j in range(0, N - 1, 2):
		D.append(A[j + 1] - A[j])
	for j in range(1, N - 1, 2):
		E.append(A[j] - A[j + 1])
	curr_best = 0
	D_ind = 0
	curr_sum = 0
	while D_ind < len(D):
		curr_sum += D[D_ind]
		curr_best = max(curr_sum, curr_best)
		if curr_sum < 0:
			curr_sum = 0
		D_ind += 1
	E_ind = 0
	curr_sum = 0
	while E_ind < len(E):
		curr_sum += E[E_ind]
		curr_best = max(curr_sum, curr_best)
		if curr_sum < 0:
			curr_sum = 0
		E_ind += 1
	return evens + curr_best
for _ in range(getInt()):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	diff = []
	s = sum(ar[::2])
	for i in range(1, n):
		if i % 2:
			diff.append(ar[i] - ar[i - 1])
		else:
			diff.append(ar[i - 1] - ar[i])
	(a, b) = (diff[::2], diff[1::2])
	(s1, m1) = (0, 0)
	for i in a:
		s1 = max(s1 + i, 0)
		m1 = max(m1, s1)
	(s2, m2) = (0, 0)
	for i in b:
		s2 = max(s2 + i, 0)
		m2 = max(m2, s2)
	su = max(m1, m2, 0)
	print(su + s)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	ma = 0
	c = 0
	for i in range(1, n, 2):
		c += a[i] - a[i - 1]
		if c < 0:
			c = 0
		ans += a[i - 1]
		ma = max(ma, c)
	c = 0
	for i in range(2, n, 2):
		c += a[i - 1] - a[i]
		if c < 0:
			c = 0
		ma = max(ma, c)
	if n % 2 == 1:
		ans += a[-1]
	print(ans + ma)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def func(arr):
	ans = 0
	currsum = 0
	for i in arr:
		if currsum + i > i:
			currsum += i
		else:
			currsum = i
		ans = max(currsum, ans)
	return ans

def solve():
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		even_ = [arr[i + 1] - arr[i] for i in range(0, n - [0, 1][n % 2 > 0], 2)]
		odd_ = [arr[i] - arr[i + 1] for i in range(1, n - [1, 0][n % 2 > 0], 2)]
		ans = 0
		for i in range(0, n, 2):
			ans += arr[i]
		ans += max(0, func(even_), func(odd_))
		print(ans)
solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count1 = 0
	maxx1 = 0
	count2 = 0
	maxx2 = 0
	summ = 0
	for i in range(1, n, 2):
		summ += a[i - 1]
		t = a[i] - a[i - 1]
		if t + count1 >= 0:
			if t < 0:
				maxx1 = max(count1, maxx1)
			count1 += t
		else:
			maxx1 = max(maxx1, count1)
			count1 = 0
		if i + 1 != n:
			t = a[i] - a[i + 1]
			if t + count2 >= 0:
				if t < 0:
					maxx2 = max(count2, maxx2)
				count2 += t
			else:
				maxx2 = max(maxx2, count2)
				count2 = 0
	if n % 2 == 1:
		summ += a[-1]
	maxx1 = max(maxx1, count1, count2, maxx2)
	print(summ + maxx1)


from functools import reduce
from math import inf

def maxSubArraySum(a):
	max_so_far = float(-inf)
	max_ending_here = 0
	for i in range(0, len(a)):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
T = int(input())
for test in range(T):
	n = int(input())
	a = [int(i) for i in input().split()]
	num0 = [0] * ((n + 1) // 2)
	num1 = [0] * (n // 2)
	num2 = [0] * ((n - 1) // 2)
	for i in range(0, n, 2):
		num0[i // 2] = a[i]
		if i < n - 1:
			num1[i // 2] = -a[i] + a[i + 1]
		if i // 2 < (n - 1) // 2:
			num2[i // 2] = a[i + 1] - a[i + 2]
	cursum = reduce(lambda x, y: x + y, num0)
	max1 = maxSubArraySum(num1)
	max2 = maxSubArraySum(num2)
	print(cursum + max(max1, max2, 0))


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	if n == 1:
		print(li[0])
		continue
	dp = [0 for i in range(n)]
	dp[0] = 0
	dp[1] = li[1] - li[0]
	for i in range(2, n):
		if i % 2 == 0:
			dp[i] = max(dp[i - 2] - li[i] + li[i - 1], -li[i] + li[i - 1])
		else:
			dp[i] = max(dp[i - 2] + li[i] - li[i - 1], li[i] - li[i - 1])
	z = max(dp)
	sumi = 0
	for i in range(n):
		if i % 2 == 0:
			sumi += li[i]
	print(sumi + max(0, z))


from sys import stdout
from io import BytesIO, IOBase
from bisect import bisect_right, bisect_left
mod = 998244353
import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
from bisect import bisect_right
from collections import Counter
from math import gcd
from random import randint
mod = 10 ** 9 + 7

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		gain = []
		for i in range(1, n, 2):
			gain.append(arr[i] - arr[i - 1])
		res = sum([i for (j, i) in enumerate(arr) if j % 2 == 0])
		t_res = 0
		sum_ = 0
		for i in gain:
			sum_ += i
			if sum_ < 0:
				sum_ = 0
			else:
				t_res = max(t_res, sum_)
		r1 = res + t_res
		gain = []
		for i in range(1, n - 1, 2):
			gain.append(arr[i] - arr[i + 1])
		res = sum([i for (j, i) in enumerate(arr) if j % 2 == 0])
		t_res = 0
		sum_ = 0
		for i in gain:
			sum_ += i
			if sum_ < 0:
				sum_ = 0
			else:
				t_res = max(t_res, sum_)
		print(max(r1, res + t_res))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def max_list(l):
	if len(l) == 1:
		return l[0]
	elif len(l) <= 2:
		return max(l[0], l[1])
	evens = [0]
	odds = [0]
	for p in range(len(l)):
		if p % 2 == 0:
			evens.append(evens[-1] + l[p])
			odds.append(odds[-1])
		else:
			odds.append(odds[-1] + l[p])
			evens.append(evens[-1])
	combined = [evens[a] - odds[a] for a in range(len(evens))]
	min_combined_even = [2 * ((len(combined) - 1) // 2) for i in range(len(combined))]
	min_combined_odd = [2 * (len(combined) // 2 - 1) + 1 for i in range(len(combined))]
	for i in range(len(combined) - 2, -1, -1):
		if i % 2 == 0:
			if combined[i] <= combined[min_combined_even[i + 1]]:
				min_combined_even[i] = i
			else:
				min_combined_even[i] = min_combined_even[i + 1]
			min_combined_odd[i] = min_combined_odd[i + 1]
		else:
			if combined[i] <= combined[min_combined_odd[i + 1]]:
				min_combined_odd[i] = i
			else:
				min_combined_odd[i] = min_combined_odd[i + 1]
			min_combined_even[i] = min_combined_even[i + 1]
	max_so_far = evens[-1]
	for i in range(len(combined)):
		if i % 2 == 0:
			max_so_far = max(max_so_far, combined[i] - combined[min_combined_even[i]] + evens[-1])
		else:
			max_so_far = max(max_so_far, combined[i] - combined[min_combined_odd[i]] + evens[-1])
	return max_so_far
t = int(input())
for i in range(t):
	n = int(input())
	print(max_list(list(map(int, input().split()))))


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n = II()
	l = LI()
	m = 0
	s = 0
	su = 0
	for i in range(n):
		if i % 2 == 0:
			su += l[i]
	for i in range(0, n - 1, 2):
		s += l[i + 1] - l[i]
		if s > m:
			m = s
		elif s < 0:
			s = 0
	s = 0
	for i in range(2, n, 2):
		s += l[i - 1] - l[i]
		if s > m:
			m = s
		elif s < 0:
			s = 0
	print(su + m)


from sys import stdin, setrecursionlimit
import threading
input = lambda : stdin.readline().rstrip('\r\n')
from collections import defaultdict as vector
from collections import deque as que
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))

def maxSubArraySum(even, odd, size):
	max_so_far = 0
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += odd[i] - even[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def main():
	Testcase = inin()
	for _ in range(Testcase):
		n = inin()
		arr = inar()
		ans = 0
		if n % 2:
			n += 1
			arr.append(0)
		even = []
		odd = []
		for i in range(n):
			if i % 2:
				odd.append(arr[i])
			else:
				even.append(arr[i])
				ans += arr[i]
		cpy = ans
		ans += maxSubArraySum(even, odd, len(even))
		odd = [0] + odd[:-1]
		ans = max(ans, cpy + maxSubArraySum(even, odd, len(even)))
		print(ans)
setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(s, e) = (None, None)
	maxi = 0
	curr = 0
	si = None
	for i in range(0, n - 1, 2):
		if curr == 0:
			si = i
		curr += a[i + 1] - a[i]
		if curr <= 0:
			si = None
			curr = 0
		elif curr > maxi:
			maxi = curr
			(s, e) = (si, i + 1)
	curr = 0
	si = None
	for i in range(1, n - 1, 2):
		if curr == 0:
			si = i
		curr += a[i] - a[i + 1]
		if curr <= 0:
			(si, ei) = (None, None)
			curr = 0
		elif curr > maxi:
			maxi = curr
			(s, e) = (si, i + 1)
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += a[i]
	if s != None and e != None:
		a[s:e + 1] = a[s:e + 1][::-1]
	ans1 = 0
	for i in range(n):
		if i % 2 == 0:
			ans1 += a[i]
	ans = max(ans, ans1)
	print(str(ans) + '\n')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	s1 = 0
	odd = []
	even = []
	for i in range(n):
		if i % 2 == 0:
			even.append(a[i])
		else:
			odd.append(a[i])
	odd1 = odd[:]
	for i in range(len(odd)):
		odd[i] -= even[i]
	for i in range(len(even) - 1):
		odd1[i] -= even[i + 1]
	if len(even) == len(odd1):
		odd1[-1] = 0
	maxi = 0
	curr = 0
	for i in odd:
		curr += i
		if curr > maxi:
			maxi = curr
		if curr < 0:
			curr = 0
	curr = 0
	for i in odd1:
		curr += i
		if curr > maxi:
			maxi = curr
		if curr < 0:
			curr = 0
	print(sum(even) + maxi)


N = eval(input())
for _ in range(N):
	n = eval(input())
	a = list(map(int, input().split()))
	c = a[0]
	odd = 0
	even = 0
	sol = 0
	for i in range(1, n):
		if i % 2 == 1:
			os = a[i] - a[i - 1]
			odd += os
			sol = max(sol, odd)
			if odd < 0:
				odd = 0
		else:
			es = a[i] - a[i - 1]
			even -= es
			sol = max(sol, even)
			c += a[i]
			if even < 0:
				even = 0
	print(c + sol)


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	li = []
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += arr[i]
	for i in range(1, n, 2):
		li.append((i - 1, arr[i] - arr[i - 1]))
	temp = 0
	if len(li) != 0:
		m = -10 ** 18
		min_so_far = 0
		a = 0
		b = 0
		c = 0
		p = 0
		for i in range(len(li)):
			p += li[i][1]
			x = p - min_so_far
			if x > m:
				m = x
				b = li[i][0] + 1
				c = a
			if p < min_so_far:
				min_so_far = p
				a = li[i][0] + 2
		if m > 0:
			for i in range(c, b + 1):
				if i % 2 != 0:
					temp += arr[i]
			for i in range(c):
				if i % 2 == 0:
					temp += arr[i]
			for i in range(b + 1, n):
				if i % 2 == 0:
					temp += arr[i]
	ans = max(ans, temp)
	li = []
	for i in range(2, n, 2):
		li.append((i - 1, arr[i - 1] - arr[i]))
	temp = 0
	if len(li) != 0:
		m = -10 ** 18
		min_so_far = 0
		a = 1
		c = 0
		b = 0
		p = 0
		for i in range(len(li)):
			p += li[i][1]
			x = p - min_so_far
			if x > m:
				m = x
				b = li[i][0] + 1
				c = a
			if p < min_so_far:
				min_so_far = p
				a = li[i][0] + 2
		if m > 0:
			for i in range(c, b + 1):
				if i % 2 != 0:
					temp += arr[i]
			for i in range(c):
				if i % 2 == 0:
					temp += arr[i]
			for i in range(b + 1, n):
				if i % 2 == 0:
					temp += arr[i]
	ans = max(ans, temp)
	print(ans)


from sys import *
input = stdin.readline

def maxSubArraySum(a, size):
	max_so_far = -1e+28 - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for _ in range(int(input())):
	n = int(input())
	k = n
	a = list(map(int, input().split()))
	b = []
	c = []
	for i in range(1, n, 2):
		b.append(a[i] - a[i - 1])
	mxb = maxSubArraySum(b, len(b))
	mxc = 0
	if n % 2 == 0:
		n -= 1
	for i in range(n - 2, -1, -2):
		c.append(a[i] - a[i + 1])
	mxc = maxSubArraySum(c, len(c))
	mx = max(mxb, mxc, 0)
	sn = 0
	for i in range(0, k, 2):
		sn += a[i]
	sn += mx
	stdout.write(str(sn) + '\n')


def lagade_kadane(A):
	max_end = 0
	max_far = -1e+18
	for i in range(len(A)):
		max_end += A[i]
		if max_end < 0:
			max_end = 0
		if max_far < max_end:
			max_far = max_end
	return max_far
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	O = []
	E = []
	sum = 0
	for i in range(0, n, 2):
		sum += A[i]
	for i in range(0, n, 2):
		if i + 1 == n:
			break
		E.append(A[i + 1] - A[i])
	for i in range(1, n, 2):
		if i + 1 == n:
			break
		O.append(A[i] - A[i + 1])
	ans = max(sum, lagade_kadane(E) + sum, lagade_kadane(O) + sum)
	print(ans)


from sys import stdin

def maxSubArraySum(a, size):
	max_so_far = -100000000000
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def help():
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split(' ')))
	ans = 0
	for i in range(0, n, 2):
		ans += arr[i]
	arr1 = []
	arr2 = []
	for i in range(1, n - 1, 2):
		arr1.append(arr[i] - arr[i + 1])
	for i in range(0, n - 1, 2):
		arr2.append(arr[i + 1] - arr[i])
	tt = max(maxSubArraySum(arr1, len(arr1)), maxSubArraySum(arr2, len(arr2)))
	tt = max(0, tt)
	print(ans + tt)
for _ in range(int(stdin.readline())):
	help()


def maxi_sum_sub(list1):
	maxi = 0
	sum1 = 0
	i = 0
	while i < len(list1):
		if list1[i] >= 0:
			while i < len(list1) and list1[i] >= 0:
				sum1 += list1[i]
				i += 1
			maxi = max(maxi, sum1)
		else:
			while i < len(list1) and list1[i] < 0 and (sum1 >= 0):
				sum1 += list1[i]
				i += 1
			if sum1 <= 0:
				sum1 = 0
	return maxi
t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	evs = 0
	for i in range(0, n, 2):
		if i >= n:
			break
		evs += list1[i]
	list2 = list()
	list3 = list()
	for i in range(1, n, 2):
		if i >= n:
			break
		list2.append(list1[i] - list1[i - 1])
	for i in range(1, n, 2):
		if i >= n - 1:
			break
		list3.append(list1[i] - list1[i + 1])
	p = maxi_sum_sub(list2)
	q = maxi_sum_sub(list3)
	print(max(evs, evs + p, evs + q))
	t -= 1


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		n = inp()
		a = inlt()
		back = []
		fwd = []
		for i in range(1, n, 2):
			back.append(a[i] - a[i - 1])
			if i != n - 1:
				fwd.append(a[i] - a[i + 1])
		ans = 0
		for i in range(0, n, 2):
			ans = ans + a[i]

		def max_window(arr):
			curr = 0
			g_max = 0
			for i in arr:
				curr = max(curr + i, 0)
				g_max = max(g_max, curr)
			return g_max
		ans = ans + max(max_window(fwd), max_window(back))
		print(ans)
main()


def maxEvenLenSum(arr, n):
	if n < 2:
		return 0
	dp = [0 for i in range(n)]
	dp[n - 1] = 0
	dp[n - 2] = arr[n - 2] + arr[n - 1]
	for i in range(n - 3, -1, -1):
		dp[i] = arr[i] + arr[i + 1]
		if dp[i + 2] > 0:
			dp[i] += dp[i + 2]
	maxSum = max(dp)
	return maxSum
t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = []
	for i in range(n):
		if i % 2 == 0:
			B.append(A[i])
	for i in range(n):
		if i % 2 == 0:
			A[i] *= -1
	max_so_far = maxEvenLenSum(A, n)
	print(sum(B) + max_so_far)


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().strip('\n').split()))
res = []
for _ in range(int(input())):
	n = int(input())
	inp = f()
	dp = [[0 for i in range(3)] for j in range(n + 1)]
	for i in range(n):
		dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + (0 if i % 2 else inp[i]))
		if i + 2 <= n:
			dp[i + 2][1] = max(dp[i + 2][1], max(dp[i][0], dp[i][1]) + (inp[i] if i % 2 else inp[i + 1]))
		dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][0], dp[i][1], dp[i][2]) + (0 if i % 2 else inp[i]))
	ans = max(dp[n])
	res.append(ans)
print('\n'.join(map(str, res)))


from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def dice():
	dp = [0] * (n + 1)
	dp[1] = 1
	dp[0] = 1
	for i in range(2, n + 1):
		for j in range(1, 7):
			if i - j >= 0:
				dp[i] = (dp[i] + dp[i - j]) % (10 ** 9 + 7)
			else:
				break
import sys

def shut():
	import os
	shutdown = input()
	if shutdown == 'no':
		exit()
	else:
		os.system('shutdown /s /t 1')

def cost(l, r, ch, s):
	var = 0
	for i in range(l, r):
		if s[i] != ch:
			var += 1
	return var

def fxn(l, r, ch, s):
	if l + 1 == r:
		if s[l] == ch:
			return 0
		return 1
	mid = (l + r) // 2
	return min(cost(l, mid, ch, s) + fxn(mid, r, chr(ord(ch) + 1), s), fxn(l, mid, chr(ord(ch) + 1), s) + cost(mid, r, ch, s))
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	even = 0
	for i in range(0, n, 2):
		even += arr[i]
	ans = 0
	i = 0
	sum = 0
	while i < n - 1:
		sum = sum + arr[i + 1] - arr[i]
		if sum < 0:
			sum = 0
		ans = max(ans, sum)
		i += 2
	sum = 0
	j = 1
	while j < n - 1:
		sum = sum + arr[j] - arr[j + 1]
		ans = max(ans, sum)
		if sum < 0:
			sum = 0
		j += 2
	print(even + ans)


import sys
import random
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

def rlinput():
	return list(map(int, input().split()))

def trinput():
	return tuple(rinput())

def srlinput():
	return sorted(list(map(int, input().split())))

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():
	n = iinput()
	(s, mn, m, res, fp) = (0, 0, 0, 0, 0)
	q = rlinput()
	for i in range(n):
		f = fp * (i > 0)
		if i % 2 == 0:
			f -= q[i]
			s += q[i]
			res = max(res, f - mn)
			mn = min(mn, f)
		else:
			f += q[i]
			res = max(res, f - m)
			m = min(m, f)
		fp = f
	print(s + res)
for inytd in range(iinput()):
	main()


from sys import stdin, stdout
import sys
INF = 100000000000.0
import math

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
from collections import defaultdict
for _ in range(int(stdin.readline())):
	n = get_int()
	arr = get_array()
	even_sum = 0
	for i in range(n):
		if i % 2 == 0:
			even_sum += arr[i]
	max_sum1 = 0
	max_sum2 = 0
	prefix_sum = 0
	for i in range(1, n, 2):
		prefix_sum = max(prefix_sum + arr[i] - arr[i - 1], 0)
		max_sum1 = max(max_sum1, prefix_sum)
	prefix_sum = 0
	for i in range(1, n - 1, 2):
		prefix_sum = max(prefix_sum + arr[i] - arr[i + 1], 0)
		max_sum2 = max(max_sum2, prefix_sum)
	print(even_sum + max(0, max_sum1, max_sum2))


t = int(input())
for _ in range(t):
	n = int(input())
	line = input()
	ar = line.split()
	ar = [int(i) for i in ar]
	ans1 = list()
	ans2 = [0, 0]
	ans3 = list()
	ans1.append(0)
	ans3.append(0)
	for i in range(n):
		if i % 2 == 0:
			ans1.append(ans1[i] + ar[i])
		else:
			ans1.append(ans1[i] + 0)
		if i % 2 == 0 and i + 2 <= n:
			ans2.append(ar[i + 1] + max(ans1[i], ans2[i]))
		elif i + 2 <= n:
			ans2.append(ar[i] + max(ans1[i], ans2[i]))
		if i % 2 == 0:
			ans3.append(max(ans1[i], ans2[i], ans3[i]) + ar[i])
		else:
			ans3.append(max(ans1[i], ans2[i], ans3[i]) + 0)
	print(max(max(ans1), max(ans2), max(ans3)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a1 = []
	a2 = []
	for i in range(0, n - 1, 2):
		a1.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		a2.append(a[i] - a[i + 1])
	ans = 0
	tot = 0
	for i in range(len(a1)):
		tot += a1[i]
		if tot < 0:
			tot = 0
		ans = max(ans, tot)
	tot = 0
	for i in range(len(a2)):
		tot += a2[i]
		if tot < 0:
			tot = 0
		ans = max(ans, tot)
	tot = 0
	for i in range(0, n, 2):
		tot += a[i]
	print(tot + ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	es = 0
	ls = 0
	rs = 0
	s = 0
	for i in range(0, n):
		if i % 2 == 0:
			es += a[i]
	for i in range(1, n, 2):
		s = max(0, s + a[i] - a[i - 1])
		ls = max(ls, s)
	s = 0
	for i in range(1, n, 2):
		if i + 1 >= n:
			break
		else:
			s = max(0, s + a[i] - a[i + 1])
			rs = max(rs, s)
	print(max(es + ls, es + rs))


T = int(input())
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	res = 0
	temp = 0
	now = 0
	increase = 0
	for i in range(0, n, 2):
		now += arr[i]
	for i in range(0, n, 2):
		if i + 1 < n:
			temp += arr[i + 1] - arr[i]
			increase = max(increase, temp)
			temp = max(temp, 0)
	res = max(res, now + increase)
	temp = 0
	increase = 0
	for i in range(1, n, 2):
		if i + 1 < n:
			temp += arr[i] - arr[i + 1]
			increase = max(increase, temp)
			temp = max(temp, 0)
	res = max(res, now + increase)
	print(res)
	T -= 1


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = sum((arr[i] for i in range(0, n, 2)))
	temp = [0]
	if n != 1:
		temp += [max(0, arr[1] - arr[0])]
		for i in range(2, n):
			if i % 2 == 0:
				temp.append(max(0, temp[-2] + arr[i - 1] - arr[i]))
			else:
				temp.append(max(0, temp[-2] + arr[i] - arr[i - 1]))
	print(ans + max(temp))


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict

def maxSubArraySum(a, size):
	max_so_far = -10 ** 10
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = I()
for _ in range(t):
	n = I()
	l = L()
	l2 = []
	l3 = []
	ans = 0
	for i in range(0, n, 2):
		ans += l[i]
	for i in range(0, n, 2):
		if i + 1 < n:
			l2.append(l[i + 1] - l[i])
	for i in range(1, n, 2):
		if i + 1 < n:
			l3.append(l[i] - l[i + 1])
	d = maxSubArraySum(l2, len(l2))
	w = maxSubArraySum(l3, len(l3))
	if d < w:
		d = w
	print(max(ans, ans + d))


from sys import stdin, stdout
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd

def maxsubarraysum(l):
	pre = 0
	ans = float('-inf')
	for i in l:
		pre += i
		ans = max(ans, pre)
		if pre < 0:
			pre = 0
	return ans
for _ in range(it()):
	n = it()
	l = mp()
	(e, o) = ([], [])
	(es, os) = (0, 0)
	for i in range(1, n, 2):
		e.append(l[i] - l[i - 1])
	for j in range(1, n - 1, 2):
		o.append(l[j] - l[j + 1])
	for i in range(n):
		if not i & 1:
			es += l[i]
		else:
			os += l[i]
	k1 = maxsubarraysum(o)
	k2 = maxsubarraysum(e)
	k = max(k1, k2)
	if k > 0:
		es += k
	print(es)


import math
t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	lt = [int(x) for x in input().split()]
	sm = 0
	for i in range(n):
		if i % 2 == 0:
			sm += lt[i]
	aux1 = []
	for i in range(2, n, 2):
		aux1.append(lt[i - 1] - lt[i])
	aux2 = []
	for i in range(0, n - 1, 2):
		aux2.append(lt[i + 1] - lt[i])
	(cur, et) = (0, -10 ** 10)
	for a in aux1:
		cur += a
		et = max(cur, et)
		cur = max(0, cur)
	can1 = max(0, et)
	(cur, et) = (0, -10 ** 10)
	for a in aux2:
		cur += a
		et = max(cur, et)
		cur = max(0, cur)
	can2 = max(0, et)
	print(sm + max(can1, can2))


def solve(n, ar):
	ans = 0
	sum = 0
	for i in range(1, n, 2):
		sum += ar[i] - ar[i - 1]
		if ans < sum:
			ans = sum
		if sum <= 0:
			sum = 0
	sum = 0
	for i in range(2, n, 2):
		sum += -(ar[i] - ar[i - 1])
		if ans < sum:
			ans = sum
		if sum <= 0:
			sum = 0
	for i in range(0, n, 2):
		ans += ar[i]
	print(ans)
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	solve(n, ar)


def mii():
	return map(int, input().split())

def maxSubArraySum(a, size):
	max_so_far = -10000000000.0 - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for _ in range(int(input())):
	n = int(input())
	a = list(mii())
	lol = []
	lol1 = []
	s = 0
	for i in range(1, n, 2):
		s += a[i - 1]
		lol.append(a[i] - a[i - 1])
		if i > 1:
			lol1.append(a[i - 2] - a[i - 1])
	if n % 2:
		s += a[-1]
		if n > 1:
			lol1.append(a[-2] - a[-1])
	print(s + max(max(0, maxSubArraySum(lol, len(lol))), max(0, maxSubArraySum(lol1, len(lol1)))))


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
v = []
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	v.append(x)
inf = -10 ** 18
for i in range(t):
	dpx = [inf] * len(v[i])
	dpy = [inf] * len(v[i])
	ans = 0
	for j in range(len(v[i]) - 1):
		if j % 2 == 0:
			cnt = v[i][j + 1] - v[i][j]
			dpx[j // 2 + 1] = max(dpx[j // 2] + cnt, cnt)
		else:
			cnt = -v[i][j + 1] + v[i][j]
			dpy[j // 2 + 1] = max(dpy[j // 2] + cnt, cnt)
	for j in range(len(v[i])):
		if j % 2 == 0:
			ans += v[i][j]
	ans += max(max(dpx), max(dpy), 0)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if n % 2:
		l.append(0)
	dp = [[0] * 4 for i in range((n + 1) // 2 + 1)]
	for i in range((n + 1) // 2):
		dp[i + 1][0] = dp[i][0] + l[i * 2]
		dp[i + 1][1] = max(dp[i][1], dp[i][0])
		if i >= 1:
			dp[i + 1][1] += l[i * 2 - 1]
		dp[i + 1][2] = max(dp[i][0], dp[i][2]) + l[i * 2 + 1]
		dp[i + 1][3] = max(dp[i][3], dp[i][1], dp[i][2]) + l[i * 2]
	print(max(dp[-1]))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
t = 1
t = int(input())
for _ in range(t):
	n = int(input())
	lst = [int(i) for i in input().split()]
	(mx, cur) = (0, 0)
	for i in range(0, n - 1, 2):
		cur += lst[i + 1] - lst[i]
		cur = max(0, cur)
		mx = max(cur, mx)
	cur = 0
	for i in range(1, n - 1, 2):
		cur += lst[i] - lst[i + 1]
		cur = max(0, cur)
		mx = max(cur, mx)
	s = sum([lst[i] for i in range(0, n, 2)])
	print(s + mx)


for i in range(int(input())):
	am = int(input())
	arr = list(map(int, input().split()))
	nArr = []
	for i in range(am):
		if i & 1:
			nArr.append(arr[i])
		else:
			nArr.append(-arr[i])
	sums = 0
	best = 0
	for i in range(0, am - 1, 2):
		sums = max(nArr[i] + nArr[i + 1], sums + nArr[i] + nArr[i + 1])
		best = max(best, sums)
	was = best
	sums = 0
	best = 0
	for i in range(1, am - 1, 2):
		sums = max(nArr[i] + nArr[i + 1], sums + nArr[i] + nArr[i + 1])
		best = max(best, sums)
	was = max(best, was)
	s = 0
	for i in range(0, am, 2):
		s += arr[i]
	print(s + was)


def ok(A):
	g = 0
	l = 0
	for i in range(len(A)):
		l = max(A[i], l + A[i])
		g = max(g, l)
	return g
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		if i % 2 == 0:
			s += a[i]
	odd = []
	even = []
	for i in range(0, n - 1, 2):
		even.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		odd.append(a[i] - a[i + 1])
	b = ok(odd)
	c = ok(even)
	print(s + max(b, c))


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		if n == 1:
			print(a[0])
			continue
		ans = [0, 0]
		(p, x) = (0, -1)
		s = 0
		for i in range(0, n, 2):
			s += a[i]
			if i + 1 >= n:
				break
			p += a[i + 1] - a[i]
			if x < p:
				x = p
			if p < 0:
				p = 0
		ans[0] = x
		(p, x) = (0, -1)
		for i in range(1, n, 2):
			if i + 1 >= n:
				break
			p += a[i] - a[i + 1]
			if x < p:
				x = p
			if p < 0:
				p = 0
		ans[1] = x
		print(s + max(0, max(ans)))


def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	n = int(input())
	a = read_list()
	res = 0
	tmp = 0
	s = 0
	for i in range(1, n, 2):
		s += a[i] - a[i - 1]
		res = max(res, s - tmp)
		tmp = min(tmp, s)
	tmp = 0
	s = 0
	for i in range(1, n - 1, 2):
		s += a[i] - a[i + 1]
		res = max(res, s - tmp)
		tmp = min(tmp, s)
	print(sum(a[::2]) + res)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	n = ri()
	A = rl()
	prev = 0
	max_diff = 0
	even_sum = 0
	for i in range(0, n - 1, 2):
		diff = max(0, A[i + 1] - A[i] + prev)
		max_diff = max(max_diff, diff)
		prev = diff
		even_sum += A[i]
	if n % 2 == 1:
		even_sum += A[-1]
	best = even_sum + max_diff
	prev = 0
	max_diff = 0
	for i in range(1, n - 1, 2):
		diff = max(0, A[i] - A[i + 1] + prev)
		prev = diff
		max_diff = max(max_diff, diff)
	print(max(best, even_sum + max_diff))
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


import sys

def maxSubArraySum(arr, len1):
	maxSumHere = 0
	maxSumTillNow = -1 * sys.maxsize
	for i in range(len1):
		maxSumHere += arr[i]
		if maxSumTillNow < maxSumHere:
			maxSumTillNow = maxSumHere
		if maxSumHere < 0:
			maxSumHere = 0
	return maxSumTillNow
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		print(arr[0])
	elif n % 2 == 0:
		lis1 = []
		lis2 = []
		for j in range(n):
			if j % 2 == 0:
				lis1.append(arr[j])
			else:
				lis2.append(arr[j])
		num1 = []
		num2 = [-1]
		for j in range(n // 2):
			num1.append(lis2[j] - lis1[j])
		for j in range(1, n // 2):
			num2.append(lis2[j - 1] - lis1[j])
		if max(max(num1), max(num2)) <= 0:
			print(sum(lis1))
		else:
			print(sum(lis1) + max(maxSubArraySum(num1, n // 2), maxSubArraySum(num2[1:], n // 2 - 1)))
	else:
		lis1 = []
		lis2 = []
		for j in range(n):
			if j % 2 == 0:
				lis1.append(arr[j])
			else:
				lis2.append(arr[j])
		num1 = []
		num2 = []
		for j in range(n // 2):
			num1.append(lis2[j] - lis1[j])
			num2.append(lis2[j] - lis1[j + 1])
		if max(max(num1), max(num2)) <= 0:
			print(sum(lis1))
		else:
			print(sum(lis1) + max(maxSubArraySum(num1, n // 2), maxSubArraySum(num2, n // 2)))


import sys, random
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = []
	C = []
	for i in range(0, n, 2):
		if i < n - 1:
			B.append(A[i + 1] - A[i])
	for i in range(1, n, 2):
		if i < n - 1:
			C.append(A[i] - A[i + 1])
	(ans, mv, maxv) = ([0, n - 1], 0, 0)
	(l, r) = (0, 1)
	for i in range(len(B)):
		mv = mv + B[i]
		if mv > maxv:
			r = i * 2 + 1
			ans = [l, r]
			maxv = mv
		if mv <= 0:
			l = i * 2 + 2
			mv = 0
	mv = 0
	(l, r) = (1, 2)
	for i in range(len(C)):
		mv = mv + C[i]
		if mv > maxv:
			r = i * 2 + 2
			ans = [l, r]
			maxv = mv
		if mv <= 0:
			l = (i + 1) * 2 + 1
			mv = 0
	(l, r) = (ans[0], ans[1])
	ans = 0
	for i in range(0, min(l, n), 2):
		ans = ans + A[i]
	for i in range(l, min(r + 1, n)):
		if i % 2 != 0:
			ans = ans + A[i]
	for i in range(r + 1, n):
		if i % 2 == 0:
			ans = ans + A[i]
	v = 0
	for i in range(0, n, 2):
		v = v + A[i]
	ans = max(ans, v)
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		r = sum(a[::2])
		t = []
		for i in range(n // 2):
			t.append(a[i * 2 + 1] - a[i * 2])
		u = []
		for i in range(1, (n + 1) // 2):
			u.append(a[i * 2 - 1] - a[i * 2])
		m = 0
		s = 0
		for c in t:
			s += c
			if s < 0:
				s = 0
			elif m < s:
				m = s
		s = 0
		for c in u:
			s += c
			if s < 0:
				s = 0
			elif m < s:
				m = s
		rr.append(r + m)
	return JA(rr, '\n')
print(main())


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	eve = []
	odd = []
	for i in range(1, n, 2):
		eve.append(lis[i] - lis[i - 1])
	for i in range(2, n, 2):
		odd.append(lis[i] - lis[i - 1])
	l = len(eve)
	i = j = 0
	l1 = len(odd)
	while i < l and eve[i] <= 0:
		i += 1
	while j < l1 and odd[j] >= 0:
		j += 1
	ans1 = ans2 = tmp = 0
	while i < l:
		if eve[i] >= 0:
			tmp += eve[i]
		else:
			ans1 = max(ans1, tmp)
			if tmp + eve[i] < 0:
				tmp = 0
			else:
				tmp += eve[i]
		i += 1
	ans1 = max(ans1, tmp)
	tmp = 0
	while j < l1:
		if odd[j] <= 0:
			tmp += odd[j]
		else:
			ans2 = min(ans2, tmp)
			if tmp + odd[j] > 0:
				tmp = 0
			else:
				tmp += odd[j]
		j += 1
	ans2 = abs(min(ans2, tmp))
	ans = 0
	for i in range(0, n, 2):
		if i % 2 == 0:
			ans += lis[i]
	print(max(ans1, ans2) + ans)


n = int(input())
while n > 0:
	arr = []
	t = int(input())
	arr = [int(tp) for tp in input().split()]
	ans = 0
	for i in range(t):
		if not i % 2:
			ans += arr[i]
	(dp, maxn) = (0, 0)
	for i in range(0, t, 2):
		if i + 1 < t:
			dp = max(dp + arr[i + 1] - arr[i], 0)
			maxn = max(dp, maxn)
	dp = 0
	for i in range(1, t, 2):
		if i + 1 < t:
			dp = max(dp + arr[i] - arr[i + 1], 0)
			maxn = max(dp, maxn)
	print(ans + maxn)
	n -= 1


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def maxSubArraySum(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	n = I()
	a = li()
	b = []
	c = []
	for i in range(n - 1):
		if i % 2 == 0:
			b.append(a[i + 1] - a[i])
		else:
			c.append(a[i] - a[i + 1])
	p = maxSubArraySum(b, len(b))
	q = maxSubArraySum(c, len(c))
	s = 0
	for i in range(n):
		if i % 2 == 0:
			s += a[i]
	print(max(s + p, s + q))
for _ in range(I()):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	o = [0] * n
	e = [0] * n
	e[0] = l[0]
	dp = [0] * n
	dp[0] = o[0] - e[0]
	ans = 0
	emin = min(0, dp[0])
	omin = 0
	for i in range(1, n):
		o[i] = o[i - 1]
		e[i] = e[i - 1]
		if i % 2 == 0:
			e[i] += l[i]
		else:
			o[i] += l[i]
		dp[i] = o[i] - e[i]
		if i % 2 == 0:
			temp = dp[i] - emin
			ans = max(ans, temp)
			emin = min(emin, dp[i])
		else:
			temp = dp[i] - omin
			ans = max(ans, temp)
			omin = min(omin, dp[i])
	ans += e[-1]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	init = 0
	o2 = []
	e2 = []
	for i in range(0, n, 2):
		init += a[i]
		if i < n - 1:
			o2.append(a[i + 1] - a[i])
		if i != 0:
			e2.append(a[i - 1] - a[i])
	me2 = 0
	if len(e2) > 0:
		me2 = e2[0]
		cm = e2[0]
		for i in range(1, len(e2)):
			cm = max(e2[i], cm + e2[i])
			me2 = max(me2, cm)
	mo2 = 0
	if len(o2) > 0:
		mo2 = o2[0]
		cm = o2[0]
		for i in range(1, len(o2)):
			cm = max(o2[i], cm + o2[i])
			mo2 = max(mo2, cm)
	print(max(init + max(me2, mo2), init))


line = input()
t = int(line)
for _ in range(t):
	line = input()
	n = int(line)
	line = input()
	nums = [int(i) for i in line.split(' ')]
	(evensum, oddsum) = ([0] * (n + 1), [0] * (n + 1))
	for i in range(n):
		evensum[i + 1] = evensum[i] + (nums[i] if i % 2 == 0 else 0)
		oddsum[i + 1] = oddsum[i] + (nums[i] if i % 2 == 1 else 0)
	res = evensum[-1]
	minD = 9999999999
	for i in range(0, n + 1, 2):
		res = max(res, evensum[-1] + (oddsum[i] - evensum[i]) - minD)
		minD = min(minD, oddsum[i] - evensum[i])
	minD = 9999999999
	for i in range(1, n + 1, 2):
		res = max(res, evensum[-1] + (oddsum[i] - evensum[i]) - minD)
		minD = min(minD, oddsum[i] - evensum[i])
	print(res)


def f(a):
	ans = -10 ** 20
	mx = -10 ** 20
	for i in a:
		mx = max(mx, i)
		ans = max(ans, mx - i)
	return ans
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	cum = []
	cum.append(a[0])
	sum = a[0]
	for i in range(1, n):
		if i % 2 == 0:
			cum.append(cum[-1] + a[i])
			sum = sum + a[i]
		else:
			cum.append(cum[-1] - a[i])
	evn = []
	for i in range(0, n, 2):
		evn.append(cum[i])
	od = [0]
	for i in range(1, n, 2):
		od.append(cum[i])
	print(sum + max(f(evn), f(od)))


def main():
	t = int(input())
	for g in range(t):
		n = int(input())
		values = list(map(int, input().split()))
		sums = [0 for i in range(n)]
		minimum_odd = [10 ** 9 for i in range(n)]
		minimum_even = [10 ** 9 for i in range(n)]
		sums[0] = -values[0]
		minimum_odd[0] = 0
		minimum_even[0] = -values[0]
		add = 0
		s = values[0]
		for i in range(1, n):
			if i % 2 == 0:
				sums[i] = sums[i - 1] - values[i]
				s += values[i]
				add = max(add, sums[i] - minimum_even[i - 1])
				minimum_even[i] = min(minimum_even[i - 1], sums[i])
				minimum_odd[i] = minimum_odd[i - 1]
			else:
				sums[i] = sums[i - 1] + values[i]
				add = max(add, sums[i] - minimum_odd[i - 1])
				minimum_odd[i] = min(minimum_odd[i - 1], sums[i])
				minimum_even[i] = minimum_even[i - 1]
		print(s + add)
main()


def subs(lst):
	if not lst:
		return None
	length = len(lst)
	curr_max = lst[0]
	global_max = lst[0]
	for i in range(1, length):
		curr_max = max(lst[i], curr_max + lst[i])
		global_max = max(curr_max, global_max)
	return global_max

def swap(lst):
	if len(lst) == 1:
		return lst[0]
	evens = []
	odds = []
	for i in range(len(lst)):
		if i % 2 == 0:
			evens.append(lst[i])
		else:
			odds.append(lst[i])
	diff = []
	for i in range(len(odds)):
		diff.append(odds[i] - evens[i])
	diff2 = []
	for j in range(len(odds)):
		try:
			diff2.append(odds[j] - evens[j + 1])
		except IndexError:
			pass
	addition = subs(diff)
	s = subs(diff2)
	if not s:
		s = addition - 1
	net = max(addition, s)
	if net < 0:
		return sum(evens)
	return sum(evens) + net
test = int(input())
matrix = []
for i in range(test):
	n = int(input())
	lst = list(map(lambda elem: int(elem), input().split(' ')))
	matrix.append(lst)
for lst in matrix:
	print(swap(lst))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	li = list(map(int, input().split()))
	if n > 2:
		a = []
		b = []
		k = int(n / 2)
		x = k
		y = k
		i = 0
		j = 1
		while x > 0:
			z = li[i + 1] - li[i]
			a.append(z)
			i += 2
			x -= 1
		if n % 2 == 0:
			while y > 1:
				z = li[j] - li[j + 1]
				b.append(z)
				j += 2
				y -= 1
		else:
			while y > 0:
				z = li[j] - li[j + 1]
				b.append(z)
				j += 2
				y -= 1
		for i in range(1, len(a)):
			a[i] = max(a[i], a[i - 1] + a[i])
		for i in range(1, len(b)):
			b[i] = max(b[i], b[i - 1] + b[i])
		sum = 0
		for i in range(len(li)):
			if i % 2 == 0:
				sum += li[i]
		q = max(a)
		r = max(b)
		w = max(q, r)
		if w > 0:
			sum = sum + w
		print(sum)
	elif n == 1:
		print(li[0])
	elif n == 2:
		print(max(li[0], li[1]))


def maxSubArraySum(a, size):
	if size == 0:
		return 0
	max_so_far = -10 ** 18
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
import math
t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	if n == 1:
		print(l[0])
	else:
		s = 0
		l1 = []
		l2 = []
		for i in range(0, n - 1, 2):
			s += l[i]
			l1.append(l[i + 1] - l[i])
		if n % 2 == 1:
			s += l[-1]
		for i in range(2, n, 2):
			l2.append(l[i - 1] - l[i])
		print(s + max(maxSubArraySum(l1, len(l1)), maxSubArraySum(l2, len(l2)), 0))


from math import ceil

def maxsubarrsum(a):
	cursum = 0
	maxsum = 0
	for i in range(len(a)):
		cursum = max(a[i], cursum + a[i])
		maxsum = max(maxsum, cursum)
	return maxsum
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		if i % 2 == 0:
			s += a[i]
	c = []
	for i in range(1, n, 2):
		c.append(a[i] - a[i - 1])
	d = []
	for i in range(1, n - 1, 2):
		d.append(a[i] - a[i + 1])
	x = maxsubarrsum(c)
	y = maxsubarrsum(d)
	s += max(x, y)
	print(s)


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	z = 0
	for i in range(0, n, 2):
		z += li[i]
	dp = [0 for i in range(n)]
	if n > 1:
		dp[1] = max(0, li[1] - li[0])
	if n > 2:
		dp[2] = max(0, li[1] - li[2])
	for i in range(3, n):
		if i % 2 == 0:
			dp[i] = max(0, dp[i - 2] + li[i - 1] - li[i])
		else:
			dp[i] = max(0, dp[i - 2] + li[i] - li[i - 1])
	ok = 0
	for i in dp:
		ok = max(ok, i)
	print(ok + z)


def maxsub(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_ending_here < 0:
			max_ending_here = 0
		elif max_so_far < max_ending_here:
			max_so_far = max_ending_here
	return max_so_far
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	pref1 = []
	pref2 = []
	for i in range(1, n, 2):
		pref1.append(arr[i] - arr[i - 1])
	for i in range(2, n, 2):
		pref2.append(arr[i - 1] - arr[i])
	a = maxsub(pref1, len(pref1))
	b = maxsub(pref2, len(pref2))
	ans = max(max(a, b), 0)
	for i in range(0, n, 2):
		ans += arr[i]
	print(ans)


t = int(input())
for T in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	(ans, s, mx) = (0, 0, 0)
	for i in range(0, n, 2):
		ans += a[i]
	(l1, l2) = ([], [])
	for i in range(0, n - 1, 2):
		s += a[i + 1] - a[i]
		l1.append(s)
		mx = max(mx, s)
		s = max(s, 0)
	s = 0
	for i in range(1, n - 1, 2):
		s += a[i] - a[i + 1]
		l2.append(s)
		mx = max(mx, s)
		s = max(s, 0)
	print(mx + ans)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ev = A[::2]
	od = A[1::2]
	ans = sum(ev)
	mn = cum = gain = 0
	for (a, b) in zip(ev, od):
		cum += b - a
		mn = min(mn, cum)
		gain = max(gain, cum - mn)
	mn = cum = 0
	for (a, b) in zip(ev[1:], od):
		cum += b - a
		mn = min(mn, cum)
		gain = max(gain, cum - mn)
	print(ans + gain)


def main():
	for t in range(int(input())):
		n = int(input())
		ls = [int(j) for j in input().split()]
		s = ls[0]
		ans = [0 for i in range(n)]
		for i in range(1, n):
			if i % 2 == 1:
				tmp = ls[i] - ls[i - 1]
				if i > 1:
					tmp = max(ans[i - 2] + tmp, tmp)
				tmp = max(tmp, 0)
				ans[i] = max(tmp, 0)
			else:
				s += ls[i]
		ans1 = [0 for i in range(n)]
		for i in range(0, n - 1):
			if i % 2 == 1:
				tmp = ls[i] - ls[i + 1]
				if i > 1:
					tmp = max(ans1[i - 2] + tmp, tmp)
				tmp = max(tmp, 0)
				ans1[i] = max(tmp, 0)
		print(max(max(ans), max(ans1)) + s)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	e_sum = 0
	for i in range(0, n, 2):
		e_sum += lst[i]
	mx1 = 0
	mmx1 = 0
	for i in range(0, n - 1, 2):
		tmp = lst[i + 1] - lst[i]
		mx1 = max(mx1 + tmp, 0)
		if mmx1 < mx1:
			mmx1 = mx1
	mx2 = 0
	mmx2 = 0
	for i in range(1, n - 1, 2):
		tmp = lst[i] - lst[i + 1]
		mx2 = max(mx2 + tmp, 0)
		if mmx2 < mx2:
			mmx2 = mx2
	print(e_sum + max(mmx1, mmx2))


def f(a):
	total = 0
	for i in range(0, len(a), 2):
		total += a[i]
	nb_pairs = len(a) // 2
	even_offset_profit = 0
	if nb_pairs >= 1:
		d_0 = [0] * nb_pairs
		for i in range(nb_pairs):
			d_0[i] = -a[2 * i] + a[2 * i + 1]
		s_0 = [0] * len(d_0)
		s_0[0] = d_0[0]
		for j in range(1, len(d_0)):
			s_0[j] = max(s_0[j - 1] + d_0[j], d_0[j])
		even_offset_profit = max(s_0)
	nb_pairs = (len(a) - 1) // 2
	odd_offset_profit = 0
	if nb_pairs >= 1:
		d_1 = [0] * nb_pairs
		for i in range(nb_pairs):
			d_1[i] = a[2 * i + 1] - a[2 * i + 2]
		s_1 = [0] * len(d_1)
		s_1[0] = d_1[0]
		for j in range(1, len(d_1)):
			s_1[j] = max(s_1[j - 1] + d_1[j], d_1[j])
		odd_offset_profit = max(s_1)
	return total + max(0, even_offset_profit, odd_offset_profit)
nb_tests = int(input())
for i in range(nb_tests):
	_ = input()
	a = [int(d) for d in input().split()]
	print(f(a))


def maxSubArraySum(a):
	max_so_far = -10000000000 - 1
	max_ending_here = 0
	for i in range(0, len(a)):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
for tt in range(0, t):
	n = int(input())
	ai = input().split(' ')
	a = []
	for i in range(0, n):
		a.append(int(ai[i]))
	b = []
	c = []
	i = 1
	while i < n:
		b.append(a[i] - a[i - 1])
		i += 2
	i = 1
	while i + 1 < n:
		c.append(a[i] - a[i + 1])
		i += 2
	max_so_far = max(maxSubArraySum(b), maxSubArraySum(c))
	su = 0
	for i in range(0, n):
		if i % 2 == 0:
			su += a[i]
	print(su + max(0, max_so_far))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	s1 = 0
	for i in range(0, n, 2):
		s1 += A[i]
		A[i] *= -1
	best = 0
	for s in range(2):
		i = s
		cur = 0
		while i + 2 <= n:
			cur += A[i] + A[i + 1]
			best = max(best, cur)
			if cur < 0:
				cur = 0
			i += 2
	print(s1 + best)


def maxSubArraySum(a, size):
	max_so_far = -10 ** 9 - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(x, y, ans) = ([], [], 0)
	p = n if n % 2 == 0 else n - 1
	q = n if n % 2 == 1 else n - 1
	for i in range(0, p, 2):
		x.append(arr[i + 1] - arr[i])
		ans += arr[i]
	if n % 2 == 1:
		ans += arr[n - 1]
	for i in range(1, q, 2):
		y.append(arr[i] - arr[i + 1])
	k = max(maxSubArraySum(x, len(x)), maxSubArraySum(y, len(y)), 0)
	print(ans + k)


maxint = 10 ** 10
t = int(input())

def kadane(arr):
	if len(arr) == 0:
		return 0
	add = ans = arr[0]
	for i in range(1, len(arr)):
		add += arr[i]
		if arr[i] >= add:
			add = arr[i]
		ans = max(add, ans)
	return max(ans, 0)
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(0, n, 2):
		ans += arr[i]
	(even, odd) = (list(), list())
	for i in range(0, n - 1, 2):
		even.append(arr[i + 1] - arr[i])
	for i in range(1, n - 1, 2):
		odd.append(arr[i] - arr[i + 1])
	ans += max(kadane(even), kadane(odd))
	print(ans)


import sys
from collections import defaultdict, deque, Counter
import math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def max_sabun(arr):
	tmn = 0
	ret = 0
	for ar in arr:
		if ar - tmn > ret:
			ret = ar - tmn
		if ar < tmn:
			tmn = ar
	return ret

def solve():
	n = getN()
	nums = getList()
	(sev, sod) = (0, 0)
	for i in range(n):
		if i % 2 == 0:
			sev += nums[i]
		else:
			sod += nums[i]
	ar1 = [0]
	ans = 0
	for i in range(n // 2):
		sa = nums[i * 2 + 1] - nums[i * 2]
		ar1.append(ar1[-1] + sa)
	if sev + max_sabun(ar1) > ans:
		ans = sev + max_sabun(ar1)
	ar1 = [0]
	for i in range((n - 1) // 2):
		sa = nums[i * 2 + 1] - nums[i * 2 + 2]
		ar1.append(ar1[-1] + sa)
	if sev + max_sabun(ar1) > ans:
		ans = sev + max_sabun(ar1)
	print(ans)

def main():
	n = getN()
	for _ in range(n):
		solve()
main()


from sys import stdin, stdout
import array

def input():
	return stdin.readline().strip()

def maxSum(A):
	max_so_far = 0
	max_ending_here = 0
	for a in A:
		max_ending_here = max_ending_here + a
		if max_ending_here < 0:
			max_ending_here = 0
		elif max_so_far < max_ending_here:
			max_so_far = max_ending_here
	return max_so_far

def ans(A):
	base = 0
	i = 0
	a1 = array.array('q')
	a2 = array.array('q')
	while i < len(A):
		base += A[i]
		if i + 1 < len(A):
			a1.append(A[i + 1] - A[i])
		i += 2
	i = 1
	while i < len(A):
		if i + 1 < len(A):
			a2.append(A[i] - A[i + 1])
		i += 2
	return base + max(maxSum(a1), maxSum(a2))
T = int(input())
for _ in range(T):
	input()
	A = input().split(' ')
	A = list(map(int, A))
	print(ans(A))


import math
math.inf

def kandane(ans):
	maxa1 = -1 * math.inf
	maxa2 = 0
	for i in range(len(ans)):
		maxa2 += ans[i]
		if maxa1 < maxa2:
			maxa1 = maxa2
		if maxa2 < 0:
			maxa2 = 0
	return maxa1
a = int(input())
for i in range(a):
	x = int(input())
	z = list(map(int, input().split()))
	i = 0
	ans = []
	while i < len(z):
		if i + 1 < len(z):
			ans.append(z[i + 1] - z[i])
		i += 2
	su = sum(z[0::2])
	ans1 = su + max(kandane(ans), 0)
	ans = []
	i = 1
	while i < len(z):
		if i + 1 < len(z):
			ans.append(-z[i + 1] + z[i])
		i += 2
	ans2 = su + max(kandane(ans), 0)
	print(max(ans1, ans2))


from sys import stdin, stdout

def maxium_sum_on_even_positions(n, a):
	esum = 0
	res1 = 0
	dif1 = 0
	res2 = 0
	dif2 = 0
	for i in range(0, n, 2):
		esum += a[i]
		if i + 1 < n:
			dif1 = max(0, dif1 + a[i + 1] - a[i])
			res1 = max(res1, dif1)
		if i > 0:
			dif2 = max(0, dif2 + a[i - 1] - a[i])
			res2 = max(res2, dif2)
	return max(esum, esum + max(res1, res2))
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	stdout.write(str(maxium_sum_on_even_positions(n, a)) + '\n')


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 0 or n % 2 == 1:
		xx = [0] * (n - 1)
		for i in range(n - 1):
			if i % 2 == 0:
				xx[i] = a[i + 1] - a[i]
			else:
				xx[i] = a[i] - a[i + 1]
		a1 = []
		a2 = []
		(x, y) = (0, 0)
		(xma, yma) = (0, 0)
		ans = 0
		for i in range(n - 1):
			if i % 2 == 0:
				x += xx[i]
				xma = max(xma, x)
				if x < 0:
					x = 0
			else:
				y += xx[i]
				yma = max(yma, y)
				if y < 0:
					y = 0
		ans = 0
		for i in range((n + 1) // 2):
			ans += a[i * 2]
		print(ans + max(0, xma, yma))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	ans1 = 0
	i = 0
	ans2 = 0
	ans3 = 0
	while i <= len(l) - 2:
		if ans + (l[i + 1] - l[i]) > 0 and i % 2 == 0:
			ans1 = max(ans, ans1)
			ans += l[i + 1]
			ans -= l[i]
			ans1 = max(ans, ans1)
		elif i % 2 != 1:
			ans = 0
		if ans2 + (l[i] - l[i + 1]) > 0 and i % 2 != 0:
			ans3 = max(ans2, ans3)
			ans2 += l[i]
			ans2 -= l[i + 1]
			ans3 = max(ans2, ans3)
		elif i % 2 != 0:
			ans2 = 0
		i += 1
	ans1 = max(ans1, ans3)
	for i in range(len(l)):
		if i % 2 == 0:
			ans1 += l[i]
	print(ans1)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		n = II()
		aa = LI()
		cs = [0]
		for i in range(2, n, 2):
			cs.append(cs[-1] + aa[i - 1] - aa[i])
		mn = 0
		v1 = 0
		for s in cs:
			v1 = max(v1, s - mn)
			mn = min(s, mn)
		cs = [0]
		for i in range(0, n - 1, 2):
			cs.append(cs[-1] + aa[i + 1] - aa[i])
		mn = 0
		v2 = 0
		for s in cs:
			v2 = max(v2, s - mn)
			mn = min(s, mn)
		ans = sum(aa[::2]) + max(v1, v2)
		print(ans)
main()


inp = lambda : map(int, input().split(' '))
(t,) = inp()
for _ in range(t):
	(n,) = inp()
	arr = list(inp())
	s_e = 0
	max_diff = [0, 0]
	curr_sum = [0, 0]
	for i in range(0, n, 2):
		s_e += arr[i]
		if i + 1 < n:
			curr_sum[0] += arr[i + 1] - arr[i]
			curr_sum[0] = max(0, curr_sum[0])
			max_diff[0] = max(max_diff[0], curr_sum[0])
		if i - 1 > 0:
			curr_sum[1] += arr[i - 1] - arr[i]
			curr_sum[1] = max(0, curr_sum[1])
			max_diff[1] = max(max_diff[1], curr_sum[1])
	print(s_e + max(max_diff))


def kadane(arr):
	s = 0
	maxi = 0
	for i in arr:
		s = max(0, s + i)
		maxi = max(maxi, s)
	return maxi
t = int(input())
for _ in range(0, t):
	n = int(input())
	aa = [int(i) for i in input().split()]
	ss = sum([aa[i] for i in range(0, n, 2)])
	diff1 = [aa[i] - aa[i - 1] for i in range(1, n, 2)]
	diff2 = [aa[i - 1] - aa[i] for i in range(2, n, 2)]
	print(ss + max(kadane(diff1), kadane(diff2)))


def KadanesAlgorithm(a):
	res = -float('inf')
	s = 0
	for i in range(len(a)):
		s = max(s + a[i], a[i])
		res = max(s, res)
	return res
for t in range(int(input())):
	n = int(input())
	(*a,) = map(int, input().split())
	ans = 0 if (n - 1) % 2 == 1 else a[n - 1]
	(evens, odds) = ([], [])
	for i in range(n - 1):
		if i % 2 == 0:
			ans += a[i]
			evens.append(a[i + 1] - a[i])
		else:
			odds.append(a[i] - a[i + 1])
	d = max(KadanesAlgorithm(evens), KadanesAlgorithm(odds))
	ans = max(ans, ans + d)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = 0
	c = 0
	for i in range(0, n - 1, 2):
		c += a[i + 1] - a[i]
		c = max(0, c)
		m = max(c, m)
	c = 0
	for i in range(1, n - 1, 2):
		c += a[i] - a[i + 1]
		c = max(0, c)
		m = max(c, m)
	sum = 0
	for i in range(0, n, 2):
		sum += a[i]
	print(sum + m)


for test_i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(max_dif, min_pref) = (0, 0)
	cur = 0
	for i in range(n // 2):
		cur += arr[i * 2 + 1] - arr[i * 2]
		if cur < min_pref:
			min_pref = cur
		elif cur - min_pref > max_dif:
			max_dif = cur - min_pref
	min_pref = 0
	cur = 0
	for i in range((n - 1) // 2):
		cur += arr[i * 2 + 1] - arr[i * 2 + 2]
		if cur < min_pref:
			min_pref = cur
		elif cur - min_pref > max_dif:
			max_dif = cur - min_pref
	sum_even = sum(arr[::2])
	print(sum_even + max_dif)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	se = 0
	for i in range(n):
		if i % 2 == 0:
			se += l[i]
	cs = 0
	ans = se
	for i in range(1, n, 2):
		cs += l[i] - l[i - 1]
		if cs < 0:
			cs = 0
		else:
			ans = max(ans, se + cs)
	cs = 0
	for i in range(1, n, 2):
		if i + 1 < n:
			cs += l[i] - l[i + 1]
			if cs < 0:
				cs = 0
			else:
				ans = max(ans, se + cs)
	print(ans)


def contiguous_subset(arr):
	cur = 0
	best = 0
	for i in arr:
		cur = max(cur + i, 0)
		best = max(cur, best)
	return best

def best_evens(arr):
	if len(arr) == 1:
		return arr[0]
	left_flip = [arr[i - 1] - arr[i] for i in range(2, len(arr), 2)]
	right_flip = [arr[i + 1] - arr[i] for i in range(0, len(arr) - 1, 2)]
	sum_evens = sum(arr[::2])
	return sum_evens + max(contiguous_subset(left_flip), contiguous_subset(right_flip))
t = int(input())
for _ in range(t):
	a = input()
	a = [int(i) for i in input().split()]
	print(best_evens(a))


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()

def kad(a):
	n = len(a)
	if n == 0:
		return 0
	v = a[0]
	for i in range(1, n):
		a[i] = max(a[i], a[i] + a[i - 1])
		v = max(v, a[i])
	return v
for _ in range(t):
	(n,) = gil()
	a = gil()
	e = sum([a[i] * (~i & 1) for i in range(n)])
	ev = []
	for i in range(1, n, 2):
		ev.append(a[i] - a[i - 1])
	od = []
	for i in range(2, n, 2):
		od.append(a[i - 1] - a[i])
	print(e + max(0, kad(od), kad(ev)))


import sys
input = sys.stdin.readline

def kadane(l):
	max_so_far = 0
	max_ending_here = 0
	for i in range(len(l)):
		max_ending_here = max_ending_here + l[i]
		if max_ending_here < 0:
			max_ending_here = 0
		elif max_so_far < max_ending_here:
			max_so_far = max_ending_here
	return max_so_far
t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	if n == 1:
		print(a[0])
	elif n == 2:
		print(max(a[1], a[0]))
	else:
		evensum = 0
		for i in range(0, n, 2):
			evensum += a[i]
		(freq1, freq2) = ([], [])
		freq1.append(max(0, a[1] - a[0]))
		freq2.append(max(0, a[1] - a[2]))
		for i in range(3, n, 2):
			freq1.append(a[i] - a[i - 1])
		if not n & 1:
			n = n - 1
		for i in range(3, n, 2):
			freq2.append(a[i] - a[i + 1])
		(p, q) = (kadane(freq1), kadane(freq2))
		print(evensum + max(p, q))


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	su = 0
	for i in range(0, n, 2):
		su += l[i]
		l[i] = l[i] * -1
	ans = 0
	for i in range(2):
		x = i
		a = 0
		while x + 2 <= n:
			a += l[x] + l[x + 1]
			ans = max(ans, a)
			a = max(0, a)
			x += 2
	print(su + ans)


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)
if is_it_local():

	def debug(*args):
		st = ''
		for arg in args:
			st += f'{arg} '
		print(st)
else:

	def debug(*args):
		pass

def main():
	t = input1()
	for ci in range(t):
		n = input1()
		arr = input_array()
		now = 0
		for i in range(0, n, 2):
			now += arr[i]
		o1 = []
		for i in range(0, n, 2):
			if i + 1 < n:
				o1.append(arr[i + 1] - arr[i])
		o2 = []
		for i in range(1, n, 2):
			if i + 1 < n:
				o2.append(arr[i] - arr[i + 1])
		cum = 0
		mx = 0
		for v in o1:
			cum += v
			cum = max(cum, 0)
			mx = max(cum, mx)
		cum = 0
		for v in o2:
			cum += v
			cum = max(cum, 0)
			mx = max(cum, mx)
		print(mx + now)
	pass
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	dp = []
	for j in range(n + 1):
		dp.append([0, 0, 0])
	for j in range(n):
		if j % 2 == 0:
			k = l[j]
			if j + 1 < n:
				k2 = l[j + 1]
		else:
			k = 0
			k2 = l[j]
		dp[j + 1][0] = max(dp[j + 1][0], dp[j][0] + k)
		if j + 2 <= n:
			dp[j + 2][1] = max(dp[j + 2][1], max(dp[j][0], dp[j][1]) + k2)
		dp[j + 1][2] = max(dp[j + 1][2], max(dp[j][0], dp[j][1], dp[j][2]) + k)
	print(max(dp[n][0], dp[n][1], dp[n][2]))


import sys
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	lr = []
	rl = []
	ans = 0
	plus_lr = 0
	last_lr = 0
	plus_rl = 0
	last_rl = 0
	for i in range(0, n, 2):
		ans += a[i]
		if i + 1 < n:
			e = a[i + 1] - a[i]
			last_lr = max(e, last_lr + e)
			if last_lr > plus_lr:
				plus_lr = last_lr
		if i - 1 >= 0:
			e = a[i - 1] - a[i]
			last_rl = max(e, last_rl + e)
			if last_rl > plus_rl:
				plus_rl = last_rl
	print(ans + max(plus_rl, plus_lr))


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	n = int(input())
	A = int_input()
	res = 0
	for i in range(0, len(A), 2):
		res += A[i]
	c1 = []
	c2 = []
	for i in range(1, len(A), 2):
		c1.append(A[i] - A[i - 1])
		if i != len(A) - 1:
			c2.append(A[i] - A[i + 1])
	m = 0
	cur = 0
	for x in c1:
		cur = max(x, x + cur)
		m = max(m, cur)
	cur = 0
	for x in c2:
		cur = max(x, x + cur)
		m = max(m, cur)
	print(res + m)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	tot = 0
	dif1 = 0
	extra = 0
	for i in range(0, n, 2):
		tot += a[i]
	for i in range(0, n - 1, 2):
		dif1 -= a[i]
		dif1 += a[i + 1]
		extra = max(extra, dif1)
		if dif1 < 0:
			dif1 = 0
	dif2 = 0
	for i in range(1, n - 1, 2):
		dif2 += a[i]
		dif2 -= a[i + 1]
		extra = max(extra, dif2)
		if dif2 < 0:
			dif2 = 0
	tot = tot + extra
	print(tot)


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))

def maxSubArrSum(arr):
	maxSoFar = 0
	maxEnding = 0
	for i in arr:
		maxEnding += i
		if maxEnding > 0:
			maxSoFar = max(maxSoFar, maxEnding)
		else:
			maxEnding = 0
	return maxSoFar
for t in range(int(input())):
	n = int(input())
	arr = intInp()
	initSum = 0
	rightProfit = []
	leftProfit = []
	for i in range(n):
		if i % 2 == 0:
			initSum += arr[i]
		if i + 1 < n and i % 2 == 0:
			rightProfit.append(arr[i + 1] - arr[i])
		if i > 1 and i % 2 == 0:
			leftProfit.append(arr[i - 1] - arr[i])
	print(initSum + max(maxSubArrSum(rightProfit), maxSubArrSum(leftProfit)))


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7

class SegTree:

	def __init__(self, n, func, intv, A=[]):
		self.n = n
		self.func = func
		self.intv = intv
		n2 = 1
		while n2 < n:
			n2 <<= 1
		self.n2 = n2
		self.tree = [self.intv] * (n2 << 1)
		if A:
			for i in range(n):
				self.tree[n2 + i] = A[i]
			for i in range(n2 - 1, -1, -1):
				self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

	def update(self, i, x):
		i += self.n2
		self.tree[i] = x
		while i > 0:
			i >>= 1
			self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1])

	def add(self, i, x):
		self.update(i, self.get(i) + x)

	def query(self, a, b):
		l = a + self.n2
		r = b + self.n2
		s = self.intv
		while l < r:
			if r & 1:
				r -= 1
				s = self.func(s, self.tree[r])
			if l & 1:
				s = self.func(s, self.tree[l])
				l += 1
			l >>= 1
			r >>= 1
		return s

	def get(self, i):
		return self.tree[i + self.n2]

	def all(self):
		return self.tree[1]

	def print(self):
		for i in range(self.n):
			print(self.get(i), end=' ')
		print()
for _ in range(INT()):
	N = INT()
	A = LIST()
	B1 = []
	B2 = []
	for i in range(N - 1):
		if i % 2 == 0:
			B1.append(A[i + 1] - A[i])
		else:
			B2.append(A[i] - A[i + 1])
	acc1 = [0] + list(accumulate(B1))
	acc2 = [0] + list(accumulate(B2))
	N1 = len(acc1)
	N2 = len(acc2)
	st1 = SegTree(N1, max, -INF, acc1)
	st2 = SegTree(N2, max, -INF, acc2)
	base = sum([a if i % 2 == 0 else 0 for (i, a) in enumerate(A)])
	ans = base
	for i in range(N1 - 1):
		l = acc1[i]
		r = st1.query(i + 1, N1)
		ans = max(ans, base + r - l)
	for i in range(N2 - 1):
		l = acc2[i]
		r = st2.query(i + 1, N2)
		ans = max(ans, base + r - l)
	print(ans)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	n = int(input())
	arr = list_input()
	summ = 0
	for i in range(0, n, 2):
		summ += arr[i]
	arr1 = []
	for i in range(1, n, 2):
		arr1.append(arr[i] - arr[i - 1])
	arr2 = []
	for i in range(1, n, 2):
		if i + 1 < n:
			arr2.append(arr[i] - arr[i + 1])
	temp1 = max(maxSubArraySum(arr1, len(arr1)), 0)
	temp2 = max(maxSubArraySum(arr2, len(arr2)), 0)
	print(summ + max(temp1, temp2))
t = 1
t = int(input())
for _ in range(t):
	solve()


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	a = inlt()
	start = 0
	max_total = 0
	max_start = -1
	max_end = -1
	while start < n - 1 and a[start] >= a[start + 1]:
		start += 2
	if start < n - 1 and a[start] < a[start + 1]:
		end = start + 1
		total = a[end] - a[start]
		max_total = total
		max_start = start
		max_end = end
		end += 2
		while end < n:
			total += a[end] - a[end - 1]
			if total < 0:
				start = end + 1
				total = 0
			elif total > max_total:
				max_total = total
				max_start = start
				max_end = end
			end = end + 2
	start = 1
	while start < n - 1 and a[start] <= a[start + 1]:
		start += 2
	if start < n - 1 and a[start] > a[start + 1]:
		end = start + 1
		total = a[start] - a[end]
		if total > max_total:
			max_total = total
			max_start = start
			max_end = end
		end += 2
		while end < n:
			total += a[end - 1] - a[end]
			if total < 0:
				start = end + 1
				total = 0
			elif total > max_total:
				max_total = total
				max_start = start
				max_end = end
			end = end + 2
	ans = 0
	for i in range(0, n, 2):
		ans += a[i]
	ans += max_total
	print(ans)


import math

def maxSubArraySum(a, size):
	max_so_far = int(-1e-19)
	max_ending_here = 0
	st = 0
	ef = 0
	et = 0
	sf = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			ef = i
			sf = st
		if max_ending_here < 0:
			max_ending_here = 0
			st = i + 1
	return (max_so_far, sf, ef)
for _ in range(int(input())):
	[n] = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = []
	for i in range(0, n, 2):
		if i + 1 < n:
			b.append(a[i + 1] - a[i])
	(a1, s, e) = maxSubArraySum(b, len(b))
	if a1 > 0:
		a1 = 0
		for i in range(0, n, 2):
			if i < 2 * s or i > 2 * e:
				a1 += a[i]
			else:
				a1 += a[i + 1]
	else:
		a1 = 0
		for i in range(0, n, 2):
			a1 += a[i]
	b = []
	for i in range(1, n, 2):
		if i + 1 < n:
			b.append(a[i] - a[i + 1])
	(a2, s, e) = maxSubArraySum(b, len(b))
	if a2 > 0:
		a2 = 0
		for i in range(0, n, 2):
			if i < 2 * (s + 1) or i > 2 * (e + 1):
				a2 += a[i]
			else:
				a2 += a[i - 1]
	else:
		a2 = 0
		for i in range(0, n, 2):
			a2 += a[i]
	print(max(a1, a2))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	diff1 = []
	diff2 = []
	evensum = 0
	for i in range(1, n, 2):
		diff1.append(arr[i] - arr[i - 1])
	for i in range(1, n - 1, 2):
		diff2.append(arr[i] - arr[i + 1])
	for i in range(0, n, 2):
		evensum += arr[i]
	m1 = 0
	m2 = 0
	l = 0
	r = 0
	s = 0
	for i in range(len(diff1)):
		s += diff1[i]
		if s < 0:
			s = 0
		if m1 < s:
			m1 = s
	s = 0
	for i in range(len(diff2)):
		s += diff2[i]
		if s < 0:
			s = 0
		if m2 < s:
			m2 = s
	print(evensum + max(m1, m2))


import sys
input = sys.stdin.buffer.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		even_s = 0
		for i in range(0, n, 2):
			even_s += a[i]
		left = []
		right = []
		for i in range(n // 2):
			left.append(a[i * 2 + 1] - a[i * 2])
		for i in range(1, (n - 1) // 2 + 1):
			right.append(a[i * 2 - 1] - a[i * 2])
		mx1 = 0
		curr = 0
		for i in range(len(left)):
			curr = max(curr + left[i], left[i])
			mx1 = max(curr, mx1)
		mx2 = 0
		curr = 0
		for i in range(len(right)):
			curr = max(curr + right[i], right[i])
			mx2 = max(curr, mx2)
		even_s += max(mx2, mx1)
		sys.stdout.write(str(even_s) + '\n')
prog()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		bf = 0
		res = 0
		als = 0
		for i in range(0, n, 2):
			als += arr[i]
		for i in range(1, n, 2):
			now = arr[i] - arr[i - 1]
			if bf + now < 0:
				bf = 0
			else:
				bf += now
			res = max(res, bf)
		bf1 = 0
		for i in range(2, n, 2):
			now = arr[i - 1] - arr[i]
			if bf1 + now < 0:
				bf1 = 0
			else:
				bf1 += now
			res = max(res, bf1)
		print(als + res)
main()


n = 0
nums = list()

def solve():
	max_ending = 0
	mmax = 0
	for i in range(0, n - 1, 2):
		max_ending = max(0, max_ending + nums[i + 1] - nums[i])
		mmax = max(mmax, max_ending)
	max_ending = 0
	for i in range(1, n - 1, 2):
		max_ending = max(0, max_ending + nums[i] - nums[i + 1])
		mmax = max(mmax, max_ending)
	return mmax
cases = int(input())
while cases > 0:
	n = int(input())
	nums = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += nums[i]
	print(ans + solve())
	cases -= 1


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	smallestOdd = 0
	smallestEven = None
	sumOdd = 0
	sumEven = 0
	largest = 0
	for (i, ai) in enumerate(a):
		if i % 2 == 0:
			sumEven += ai
			if smallestEven is not None:
				largest = max(largest, sumOdd - sumEven - smallestEven)
				smallestEven = min(smallestEven, sumOdd - sumEven)
			else:
				smallestEven = sumOdd - sumEven
		else:
			sumOdd += ai
			largest = max(largest, sumOdd - sumEven - smallestOdd)
			smallestOdd = min(smallestOdd, sumOdd - sumEven)
	print(sumEven + largest)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
from bisect import bisect, bisect_right, bisect_left

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def maxi(temp):
	max_so_far = 0
	curr_sum = 0
	(ans_l, ans_r) = (0, 0)
	(l, r) = (0, 0)
	for (ind, val) in enumerate(temp):
		curr_sum += val
		if curr_sum < 0:
			curr_sum = 0
			l = ind + 1
		if curr_sum > max_so_far:
			max_so_far = curr_sum
			ans_r = ind
			ans_l = l
	if curr_sum > max_so_far:
		max_so_far = curr_sum
		ans_r = ind
		ans_l = l
	return (ans_l, ans_r)

def solve():
	n = get_int()
	ls = get_list()
	temp1 = []
	temp2 = []
	(even_index_sum, even_index_sum1, even_index_sum2) = (0, 0, 0)
	for i in range(0, n):
		if i % 2 == 0:
			if i + 1 < n:
				temp1.append(ls[i + 1] - ls[i])
			even_index_sum += ls[i]
		elif i + 1 < n:
			temp2.append(ls[i] - ls[i + 1])
	(l, r) = maxi(temp1)
	(l, r) = (l * 2, r * 2 + 1)
	ans_ls1 = ls[:l] + list(reversed(ls[l:r + 1])) + ls[r + 1:]
	even_index_sum1 = sum([val for val in ans_ls1[::2]])
	(l, r) = maxi(temp2)
	(l, r) = (l * 2 + 1, r * 2 + 2)
	ans_ls2 = ls[:l] + list(reversed(ls[l:r + 1])) + ls[r + 1:]
	even_index_sum2 = sum([val for val in ans_ls2[::2]])
	return max(even_index_sum, even_index_sum1, even_index_sum2)

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


def kadane(Arr, l, r):
	sm = 0
	x = 0
	for i in range(len(Arr)):
		x = x + Arr[i] if x + Arr[i] > 0 else 0
		sm = max(sm, x)
	return sm
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans = ans + A[i]
	L = [0]
	R = [0]
	for i in range(n):
		if i % 2 == 1:
			continue
		if i < n - 1:
			R.append(A[i + 1] - A[i])
		if i > 0:
			L.append(A[i - 1] - A[i])
	print(max(ans, ans + kadane(L, 0, len(L) - 1), ans + kadane(R, 0, len(R) - 1)))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(item) for item in input().split()]
	even_sum = sum(a[::2])
	max_total = 0
	diff = []
	for (a1, a2) in zip(a[::2], a[1::2]):
		diff.append(a2 - a1)
	total = 0
	for item in diff:
		total += item
		if item > 0:
			max_total = max(max_total, total)
		elif total < 0:
			total = 0
	diff = []
	for (a1, a2) in zip(a[1::2], a[2::2]):
		diff.append(a1 - a2)
	total = 0
	for item in diff:
		total += item
		if item > 0:
			max_total = max(max_total, total)
		elif total < 0:
			total = 0
	print(max_total + even_sum)


import sys
import math
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	origin = sum([a[i] for i in range(n) if i % 2 == 0])
	acc = [0] * (1 + n)
	for i in range(n):
		if i % 2:
			acc[i + 1] = acc[i] + a[i]
		else:
			acc[i + 1] = acc[i] - a[i]
	ans_dif = 0
	even_min = acc[0]
	for i in range(n // 2 + 1):
		even_min = min(even_min, acc[i * 2])
		ans_dif = max(ans_dif, acc[i * 2] - even_min)
	odd_min = acc[1]
	for i in range((1 + n) // 2):
		odd_min = min(odd_min, acc[i * 2 + 1])
		ans_dif = max(ans_dif, acc[i * 2 + 1] - odd_min)
	print(ans_dif + origin)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	no_reverse = [0] * (n + 1)
	cur_reverse = [0] * (n + 1)
	prev_reverse = [0] * (n + 1)
	for i in range(n):
		no_reverse[i + 1] = no_reverse[i] + (0 if i & 1 else arr[i])
		if i + 2 <= n:
			cur_reverse[i + 2] = max(no_reverse[i], cur_reverse[i]) + (arr[i] if i & 1 else arr[i + 1])
		prev_reverse[i + 1] = max(no_reverse[i], cur_reverse[i], prev_reverse[i]) + (0 if i & 1 else arr[i])
	print(max(no_reverse[-1], cur_reverse[-1], prev_reverse[-1]))


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, a):
	base = 0
	for i in range(0, n, 2):
		base += a[i]
	ans = base
	l = 0
	best = 0
	s = 0
	for r in range(n // 2):
		s += a[2 * r + 1] - a[2 * r]
		while s < 0:
			s -= a[2 * l + 1] - a[2 * l]
			l += 1
		if s > best:
			best = s
			ans = max(ans, base + best)
	l = 0
	best = 0
	s = 0
	for r in range((n - 1) // 2):
		s += a[2 * r + 1] - a[2 * r + 2]
		while s < 0:
			s -= a[2 * l + 1] - a[2 * l + 2]
			l += 1
		if s > best:
			best = s
			ans = max(ans, base + best)
	return ans

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		wi(solve(n, a))
main()


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	even = []
	i = 0
	while True:
		if i + 1 < n:
			even.append(a[i + 1] - a[i])
		else:
			break
		i += 2
	maxe = 0
	sum = 0
	for i in even:
		sum += i
		if sum < 0:
			sum = 0
		if sum > maxe:
			maxe = sum
	odd = []
	i = 1
	while True:
		if i + 1 < n:
			odd.append(a[i] - a[i + 1])
		else:
			break
		i += 2
	maxo = 0
	sum = 0
	for i in odd:
		sum += i
		if sum < 0:
			sum = 0
		if sum > maxo:
			maxo = sum
	initial = 0
	for j in range(n):
		if j % 2 == 0:
			initial += a[j]
	if maxe > maxo:
		print(initial + maxe)
	else:
		print(initial + maxo)


from sys import stdin, stdout
from sys import maxsize
input = stdin.readline

def solve():
	pass
test = 1
test = int(input().strip())
for t in range(0, test):
	n = int(input().strip())
	arr = [int(x) for x in input().strip().split()]
	val = 0
	for i in range(0, n, 2):
		val += arr[i]
	if n == 1:
		print(arr[0])
		continue
	brr = [0] * n
	brr[1] = max(0, arr[1] - arr[0])
	for i in range(2, n):
		if i % 2 == 0:
			brr[i] = max(0, brr[i - 2] - arr[i] + arr[i - 1])
		else:
			brr[i] = max(0, brr[i - 2] + arr[i] - arr[i - 1])
	print(max(val, val + max(brr)))
	ans = solve()


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	su = [-arr[0]]
	su1 = arr[0]
	for i in range(1, n):
		if i % 2 == 0:
			su.append(su[-1] - arr[i])
			su1 += arr[i]
		else:
			su.append(su[-1] + arr[i])
	ans = 0
	od_min = sum1 = 0
	ev_min = 10 ** 10
	for (ind, val) in enumerate(su):
		if ind % 2 == 0:
			ans = max(ans, val - ev_min)
		else:
			ans = max(ans, val - od_min)
		if ind % 2 == 0:
			ev_min = min(val, ev_min)
		else:
			od_min = min(val, od_min)
	print(ans + su1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sout = out = curq = 0
	for i in range(1, n - 1, 2):
		curq += a[i] - a[i + 1]
		if curq < 0:
			curq = 0
		out = max(out, curq)
	curq = 0
	for i in range(0, n - 1, 2):
		curq += a[i + 1] - a[i]
		if curq < 0:
			curq = 0
		out = max(out, curq)
	for i in range(0, n, 2):
		sout += a[i]
	print(sout + out)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(0, n, 2):
		ans += a[i]
		a[i] *= -1
	currmax = a[0]
	globmax = a[0]
	best = 0
	for x in range(2):
		y = x
		cur = 0
		while y + 2 <= n:
			cur += a[y] + a[y + 1]
			best = max(best, cur)
			if cur < 0:
				cur = 0
			y += 2
	print(ans + best)


for k in range(0, int(input())):
	a = int(input())
	l1 = list(map(int, input().split()))
	l2 = []
	l3 = []
	A = 0
	B = 0
	C = 0
	D = 0
	s1 = 0
	for u in range(0, len(l1), 2):
		s1 += l1[u]
	for i in range(0, len(l1) - 1, 2):
		l2.append(l1[i + 1] - l1[i])
	for j in range(1, len(l1) - 1, 2):
		l3.append(l1[j] - l1[j + 1])
	for l in l2:
		A += l
		if A < 0:
			A = 0
		if A > B:
			B = A
	for g in l3:
		C += g
		if C < 0:
			C = 0
		if C > D:
			D = C
	if B > D:
		print(s1 + B)
	else:
		print(s1 + D)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	n = inp()
	l = inlt()
	if len(l) == 1 or len(l) == 2:
		print(max(l))
	else:
		two_string = []
		i = 0
		while i < len(l):
			if i + 1 < len(l):
				two_string.append(l[i + 1] - l[i])
			i += 2
		cur = -10000000
		max_val = -100000000
		cur_ind_start = 0
		ind_start = 0
		ind_end = 0
		for i in range(len(two_string)):
			x = two_string[i]
			if x > cur + x:
				cur_ind_start = i
				cur = x
			else:
				cur += x
			if cur > max_val:
				ind_start = cur_ind_start
				ind_end = i
				max_val = cur
		two_string2 = []
		i = 1
		while i < len(l):
			if i + 1 < len(l):
				two_string2.append(l[i] - l[i + 1])
			i += 2
		cur2 = -100000000
		max_val2 = -1000000000
		cur_ind_start2 = 0
		ind_start2 = -1
		ind_end2 = -1
		for i in range(len(two_string2)):
			x = two_string2[i]
			if x > cur2 + x:
				cur_ind_start2 = i
				cur2 = x
			else:
				cur2 += x
			if cur2 > max_val2:
				ind_start2 = cur_ind_start2
				ind_end2 = i
				max_val2 = cur2
		ind_start *= 2
		ind_end *= 2
		ind_start2 *= 2
		ind_end2 *= 2
		res = 0
		k = 0
		if max_val <= 0 and max_val2 <= 0:
			while k < len(l):
				res += l[k]
				k += 2
		elif max_val > max_val2:
			while k < len(l):
				if k >= ind_start and k <= ind_end:
					res += l[k + 1]
				else:
					res += l[k]
				k += 2
		else:
			k = 0
			while k < len(l):
				if k >= ind_start2 + 2 and k <= ind_end2 + 2:
					res += l[k - 1]
				else:
					res += l[k]
				k += 2
		print(res)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for ___ in range(t):
	n = int(input())
	numbers = [int(x) for x in input().split()]
	if n == 1:
		print(numbers[0])
		continue
	dpEven = [[-1 for _ in range(len(numbers))] for __ in range(3)]
	dpEven[0][0] = numbers[0]
	for i in range(2, len(numbers), 2):
		dpEven[0][i] = dpEven[0][i - 2] + numbers[i]
	dpEven[1][0] = numbers[1]
	for i in range(2, len(numbers) // 2 * 2, 2):
		dpEven[1][i] = max(dpEven[1][i - 2], dpEven[0][i - 2]) + numbers[i + 1]
	dpEven[2][0] = numbers[0]
	for i in range(2, len(numbers), 2):
		dpEven[2][i] = max(dpEven[1][i - 2], dpEven[2][i - 2]) + numbers[i]
	if len(numbers) % 2 == 0:
		evenMax = max(dpEven[2][-2], dpEven[1][-2], dpEven[0][-1])
	else:
		evenMax = max(dpEven[2][-1], dpEven[1][-1], dpEven[0][-1])
	dpOdd = [[-1 for _ in range(len(numbers))] for __ in range(3)]
	dpOdd[0][0] = numbers[0]
	for i in range(2, len(numbers), 2):
		dpOdd[0][i] = dpOdd[0][i - 2] + numbers[i]
	dpOdd[1][0] = numbers[0]
	for i in range(2, len(numbers), 2):
		dpOdd[1][i] = max(dpOdd[0][i - 2], dpOdd[1][i - 2]) + numbers[i - 1]
	dpOdd[2][0] = numbers[0]
	for i in range(2, len(numbers), 2):
		dpOdd[2][i] = max(dpOdd[1][i - 2], dpOdd[2][i - 2]) + numbers[i]
	if len(numbers) % 2 == 0:
		oddMax = max(dpOdd[0][-2], dpOdd[1][-2], dpOdd[2][-2])
	else:
		oddMax = max(dpOdd[0][-1], dpOdd[1][-1], dpOdd[2][-1])
	print(max(oddMax, evenMax))


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	maxscore = 0
	twocntr = 0
	localone = 0
	localtwo = 0
	if n % 2:
		twocntr += arr[-1]
	for j in range(n - 1):
		if j % 2:
			localtwo += arr[j] - arr[j + 1]
			if localtwo > maxscore:
				maxscore = localtwo
			elif localtwo < 0:
				localtwo = 0
		else:
			twocntr += arr[j]
			localone += arr[j + 1] - arr[j]
			if localone > maxscore:
				maxscore = localone
			elif localone < 0:
				localone = 0
	print(twocntr + maxscore)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	E = [0]
	O = [0]
	INIT = 0
	for i in range(n):
		if i % 2 == 0:
			E.append(E[-1] + A[i])
			O.append(O[-1])
			INIT += A[i]
		else:
			E.append(E[-1])
			O.append(O[-1] + A[i])
	O_E = [O[i] - E[i] for i in range(n + 1)]
	MAX0 = O_E[-1]
	MAX1 = O_E[-2]
	ANS = 0
	for i in range(n, -1, -1):
		if (n - i) % 2 == 0:
			ANS = max(ANS, MAX0 - O_E[i])
			MAX0 = max(MAX0, O_E[i])
		else:
			ANS = max(ANS, MAX1 - O_E[i])
			MAX1 = max(MAX1, O_E[i])
	print(ANS + INIT)


import os, io
from sys import stdout
import collections
import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import Counter
import heapq

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	left = []
	for i in range(0, len(l) - 1, 2):
		left.append(l[i + 1] - l[i])
	right = []
	for i in range(1, len(l) - 1, 2):
		right.append(l[i] - l[i + 1])
	a = kadane(left, len(left))
	b = kadane(right, len(right))
	print(sum(l[::2]) + max(a, b))


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))

def maxSubArraySum(a, size):
	max_so_far = -99999 - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = rl()
	s = 0
	d1 = []
	d2 = []
	s1 = 0
	for i in range(0, n, 2):
		s = s + a[i]
	for i in range(0, n, 2):
		if i + 1 >= n:
			continue
		d1.append(a[i + 1] - a[i])
		if i + 2 >= n:
			continue
		d2.append(a[i + 1] - a[i + 2])
	ans1 = maxSubArraySum(d1, len(d1))
	ans2 = maxSubArraySum(d2, len(d2))
	mx = max(ans1, ans2)
	if mx > 0:
		s = s + mx
	print(s)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans11 = 0
	ans111 = 0
	i = 0
	ans211 = 0
	ans311 = 0
	while i <= len(l) - 2:
		if ans11 + (l[i + 1] - l[i]) > 0 and i % 2 == 0:
			ans111 = max(ans11, ans111)
			ans11 += l[i + 1]
			ans11 -= l[i]
			ans111 = max(ans11, ans111)
		elif i % 2 != 1:
			ans11 = 0
		if ans211 + (l[i] - l[i + 1]) > 0 and i % 2 != 0:
			ans311 = max(ans211, ans311)
			ans211 += l[i]
			ans211 -= l[i + 1]
			ans311 = max(ans211, ans311)
		elif i % 2 != 0:
			ans211 = 0
		i += 1
	for i in range(len(l)):
		tmp = 1
	ans111 = max(ans111, ans311)
	for i in range(len(l)):
		if i % 2 == 0:
			ans111 += l[i]
	print(ans111)


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def kadane(li, n):
	max_current = max_global = li[0]
	for i in range(1, n):
		max_current = max(li[i], max_current + li[i])
		if max_current > max_global:
			max_global = max_current
	return max_global
mx = 10 ** 9 + 7

def solve():
	n = II()
	li = L()
	(x, x1) = ([], [])
	kd = False
	for i in range(0, n - 1, 2):
		y = li[i + 1] - li[i]
		x.append(y)
		if y > 0:
			kd = True
	kd1 = False
	for i in range(1, n - 1, 2):
		y = li[i + 1] - li[i]
		x1.append(-y)
		if -y > 0:
			kd1 = True
	(mx1, mx2) = (0, 0)
	if kd or kd1:
		if x:
			mx1 = kadane(x, len(x))
		if x1:
			mx2 = kadane(x1, len(x1))
		mx = max(mx1, mx2)
	else:
		mx = 0
	for i in range(0, n, 2):
		mx += li[i]
	print(mx)
t = II()
for i in range(t):
	solve()


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
for t in range(int(data())):
	n = int(data())
	a = mdata()
	m = 0
	cur1 = 0
	cur2 = 0
	s = 0
	for i in range(0, n, 2):
		s += a[i]
	for i in range(1, n, 2):
		cur1 += a[i] - a[i - 1]
		if i + 1 < n:
			cur2 += a[i] - a[i + 1]
		m = max(m, cur1, cur2)
		if cur1 < 0:
			cur1 = 0
		if cur2 < 0:
			cur2 = 0
	out(s + m)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(n, A):
	k = n // 2
	DP = [[0] * 3 for _ in range(k + 1)]
	for i in range(k):
		(l, r) = (2 * i, 2 * i + 1)
		DP[i + 1][0] = DP[i][0] + A[l]
		DP[i + 1][1] = max(DP[i][0] + A[r], DP[i][1] + A[r])
		DP[i + 1][2] = max(DP[i][1] + A[l], DP[i][2] + A[l])
	ans = max(DP[-1])
	return ans

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split()))
		if n % 2:
			A.append(0)
			n += 1
		ans1 = solve(n, A)
		B = A[1:-1]
		B.reverse()
		ans2 = A[0] + solve(n - 2, B)
		ans = max(ans1, ans2)
		sys.stdout.write(str(ans) + '\n')
main()


def main():
	for case in range(int(input())):
		input()
		vs = [int(t) for t in input().strip().split()]
		max_sum = 0
		cum_sum = 0
		for i in range(len(vs) // 2):
			cum_sum = max(0, cum_sum + vs[2 * i + 1] - vs[2 * i])
			max_sum = max(max_sum, cum_sum)
		cum_sum = 0
		for i in range((len(vs) - 1) // 2):
			cum_sum = max(0, cum_sum + vs[2 * i + 1] - vs[2 * i + 2])
			max_sum = max(max_sum, cum_sum)
		print(sum((v for (i, v) in enumerate(vs) if i % 2 == 0)) + max_sum)
main()


import math

def solution(n, arr):
	if n == 1:
		return arr[0]
	sume = 0
	sumarr = []
	for i in range(n):
		sume += (-1) ** (i + 1) * arr[i]
		sumarr.append(sume)

	def sum(i):
		if i < 0:
			return 0
		return -math.inf if i >= n else sumarr[i]
	maxims = list(range(n))
	(maxims[-1], maxims[-2]) = (n, n - 1)
	for i in range(n - 3, -1, -1):
		if sum(i + 1) >= sum(maxims[i + 2]):
			maxims[i] = i + 1
		else:
			maxims[i] = maxims[i + 2]
	maximum = 0
	for i in range(n):
		if sum(maxims[i]) - sum(i - 1) > maximum:
			maximum = sum(maxims[i]) - sum(i - 1)
	sume = 0
	for i in range(0, n, 2):
		sume += arr[i]
	return sume + maximum
cases = int(input())
for case in range(cases):
	print(solution(int(input()), [int(x) for x in input().split(' ')]))


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import sys

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return list(map(str, input().strip()))

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter, deque
import math
import heapq
from heapq import heappop, heappush
import bisect
from itertools import groupby
from itertools import permutations as comb

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a // gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a):
	print('? {}'.format(a), flush=True)
	n = I()
	return n

def dfs(i, p, d):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n // i
	if n > 2:
		l.append(n)
	return l
from math import inf
t = I()
for _ in range(t):
	n = I()
	s = lint()
	ans = 0
	for i in range(0, n, 2):
		ans += s[i]
	tmp = 0
	m = 0
	for i in range(0, n - 1, 2):
		tmp += s[i + 1] - s[i]
		tmp = max(0, tmp)
		m = max(tmp, m)
	tmp = 0
	for i in range(1, n - 1, 2):
		tmp += s[i] - s[i + 1]
		tmp = max(0, tmp)
		m = max(tmp, m)
	m = max(tmp, m)
	print(ans + m)


def kadane(a):
	ans = res = 0
	for i in a:
		ans = max(ans + i, i)
		res = max(res, ans)
	return res
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	b = [a[i] - a[i - 1] for i in range(1, n, 2)]
	c = [a[i - 1] - a[i] for i in range(2, n, 2)]
	print(sum(a[::2]) + max(kadane(b), kadane(c)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ev = 0
	od = 0
	b = []
	c = []
	for i in range(n):
		if i % 2 == 0:
			ev += a[i]
		else:
			od += a[i]
	for i in range(0, n - 1, 2):
		b.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		c.append(a[i] - a[i + 1])
	ma = 0
	cur = 0
	for i in range(len(b)):
		cur += b[i]
		if cur > ma:
			ma = cur
		if cur < 0:
			cur = 0
	ma2 = 0
	cur = 0
	for i in range(len(c)):
		cur += c[i]
		if cur > ma2:
			ma2 = cur
		if cur < 0:
			cur = 0
	print(max(ev, ev + max(ma, ma2)))


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	t = I()
	for _ in range(t):
		n = I()
		a = LI()
		odd = [a[i] if i & 1 else 0 for i in range(n)]
		even = [a[i] - odd[i] for i in range(n)]
		odd = [0] + list(accumulate(odd))
		even = [0] + list(accumulate(even))
		sub = [even[i] - odd[i] for i in range(n + 1)]
		ans = max(even)
		l = 0
		k = even[1] - odd[1]
		for r in range(2, n, 2):
			s = even[n] - even[r + 1] + even[l + 1] + odd[r + 1] - odd[l + 1]
			if ans < s:
				ans = s
			p = sub[r + 1]
			if k < p:
				l = r
				k = p
		l = -1
		k = 0
		for r in range(1, n, 2):
			s = even[n] - even[r + 1] + even[l + 1] + odd[r + 1] - odd[l + 1]
			if ans < s:
				ans = s
			p = sub[r + 1]
			if k < p:
				l = r
				k = p
		print(ans)
	return
solve()


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	(mx, cur) = (0, 0)
	for i in range(0, n - 1, 2):
		cur += lst[i + 1] - lst[i]
		cur = max(0, cur)
		mx = max(cur, mx)
	cur = 0
	for i in range(1, n - 1, 2):
		cur += lst[i] - lst[i + 1]
		cur = max(0, cur)
		mx = max(cur, mx)
	s = sum([lst[i] for i in range(0, n, 2)])
	print(s + mx)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = (n + 1) // 2
	(x, y) = ([0] * m, [0] * (n // 2))
	even = 0
	for i in range(n):
		if i % 2 == 0:
			x[i // 2] = a[i]
			even += a[i]
		else:
			y[i // 2] = a[i]
	(u, v) = ([0] * m, [0] * m)
	for i in range(m):
		if not n % 2 == 1 or not i == n // 2:
			u[i] = y[i] - x[i]
		if not i == 0:
			v[i] = y[i - 1] - x[i]
	ans = 0
	(s1, s2) = (0, 0)
	for i in range(m):
		s1 = max(s1 + u[i], u[i])
		s2 = max(s2 + v[i], v[i])
		ans = max(s1, s2, ans)
	print(even + ans)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	suma = sum(l[::2])
	curr_sum = 0
	(maxi1, maxi2) = (0, 0)
	i = 0
	while i + 1 < n:
		if i % 2 == 0:
			curr_sum += l[i + 1] - l[i]
			if curr_sum < 0:
				curr_sum = 0
			if curr_sum > maxi1:
				maxi1 = curr_sum
		i += 1
	i = 2
	curr_sum = 0
	while i < n:
		if i % 2 == 0:
			curr_sum += l[i - 1] - l[i]
			if curr_sum < 0:
				curr_sum = 0
			if curr_sum > maxi2:
				maxi2 = curr_sum
		i += 1
	print(suma + max(maxi1, maxi2))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	for i in range(n):
		if i % 2 == 0:
			s += l[i]
	x = []
	for i in range(1, n, 2):
		x.append(l[i] - l[i - 1])
	prev = 0
	ma = 0
	for j in range(0, len(x)):
		prev = max(prev + x[j], x[j])
		ma = max(prev, ma)
	y = []
	for i in range(1, n, 2):
		if i + 1 >= n:
			break
		y.append(l[i] - l[i + 1])
	prev = 0
	ma1 = 0
	for j in range(0, len(y)):
		prev = max(prev + y[j], y[j])
		ma1 = max(prev, ma1)
	ans = max(ma, ma1)
	print(s + ans)


import sys
input = sys.stdin.buffer.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	Query.append((N, A))

def solve(A, ans):
	nowmin = 0
	w = 0
	for p1 in A:
		w += p1
		nowmin = min(nowmin, w)
		ans = max(ans, T + w - nowmin)
	return ans
for (N, A) in Query:
	T = 0
	P1 = []
	P2 = []
	for i in range((N - 1) // 2 + 1):
		T += A[2 * i]
		if 2 * i + 1 <= N - 1:
			d = A[2 * i + 1] - A[2 * i]
			P1.append(d)
		if 0 <= 2 * i - 1:
			d = A[2 * i - 1] - A[2 * i]
			P2.append(d)
	ans = solve(P1, T)
	ans = solve(P2, ans)
	print(ans)


import math

def solve(arr):
	n = len(arr)
	ans = -float('inf')
	ch = 0
	for i in range(n):
		ch += arr[i]
		if ans < ch:
			ans = ch
		if ch < 0:
			ch = 0
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	even = 0
	for i in range(n):
		if i % 2 == 0:
			even += a[i]
	ch1 = []
	ch2 = []
	for i in range(1, n - 1, 2):
		ch1.append(a[i] - a[i + 1])
	for i in range(1, n, 2):
		ch2.append(a[i] - a[i - 1])
	ans = max(even, solve(ch1) + even, solve(ch2) + even)
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def bfs(g, st):
	visited = [0] * len(g)
	visited[st] = 1
	queue = []
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.pop()
		new.append(s)
		for i in g[s]:
			if visited[i] == 0:
				visited[i] = 1
				queue.append(i)
	return new

def k(a):
	max_so_far = -10 ** 9
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, len(a)):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = s
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			s = i + 1
	return max_so_far

def solve():
	n = int(inp())
	a = lis()
	ans = 0
	for i in range(0, n, 2):
		ans += a[i]
	diff1 = []
	diff2 = []
	for i in range(1, n, 2):
		diff1.append(a[i] - a[i - 1])
		if i + 1 < n:
			diff2.append(a[i] - a[i + 1])
	print(max(ans + k(diff1), ans + k(diff2), ans))
testcase(int(inp()))


from math import *
tests = int(input())
for t in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	max = 0
	sum = 0
	even = 0
	for i in range(0, n, 2):
		even += a[i]
		if i + 1 >= n:
			break
		sum += a[i + 1] - a[i]
		if sum < 0:
			sum = 0
		elif sum > max:
			max = sum
	sum = 0
	for i in range(1, n, 2):
		if i + 1 >= n:
			break
		sum += a[i] - a[i + 1]
		if sum < 0:
			sum = 0
		elif sum > max:
			max = sum
	print(even + max)


def kadane_alg(a):
	max_so_far = float('-inf')
	max_ending_here = 0
	for i in range(len(a)):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far if max_so_far > 0 else 0
for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input().split()]
	i = 0
	newarr = [0 for i in range(len(arr) // 2)]
	j = 0
	while i + 1 < len(arr):
		newarr[j] = arr[i + 1] - arr[i]
		i += 2
		j += 1
	i = 1
	newarr2 = [0 for i in range(len(arr) // 2)]
	j = 0
	while i + 1 < len(arr):
		newarr2[j] = arr[i] - arr[i + 1]
		i += 2
		j += 1
	evensum = 0
	for i in range(0, len(arr), 2):
		evensum += arr[i]
	print(evensum + max(kadane_alg(newarr), kadane_alg(newarr2)))


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())

def mss(b):
	ans = 0
	msf = 0
	for i in b:
		msf = max(msf + i, 0)
		ans = max(ans, msf)
	return ans
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(0, n, 2):
		s += a[i]
	b1 = []
	b2 = []
	for i in range(0, n - 1, 2):
		b1.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		b2.append(a[i] - a[i + 1])
	print(s + max(0, mss(b1), mss(b2)))


t = int(input())
for _ in range(t):
	l = int(input())
	a = list(map(int, input().split()))
	evenSum = 0
	for i in range(l):
		if i % 2 == 0:
			evenSum += a[i]
	oddSum1 = 0
	maxOddSum1 = 0
	for i in range(1, l - 1, 2):
		oddSum1 = max(0, oddSum1 + a[i] - a[i + 1])
		maxOddSum1 = max(oddSum1, maxOddSum1)
	oddSum2 = 0
	maxOddSum2 = 0
	for i in range(1, l, 2):
		oddSum2 = max(0, oddSum2 + a[i] - a[i - 1])
		maxOddSum1 = max(oddSum2, maxOddSum1)
	ans = max(evenSum, evenSum + maxOddSum1)
	print(ans)


def solve():
	t = int(input())
	while t > 0:
		n = int(input())
		a = list(map(int, input().split()))
		f = [0 for _ in range(n + 2)]
		f[n] = 0
		mx = 0
		for pos in range(n - 2, -1, -1):
			if pos % 2 == 0:
				f[pos] = max(0, a[pos + 1] - a[pos] + f[pos + 2])
			else:
				f[pos] = max(0, a[pos] - a[pos + 1] + f[pos + 2])
			mx = max(mx, f[pos])
		sum = 0
		for i in range(0, n, 2):
			sum += a[i]
		sum = sum + mx
		print(sum)
		t -= 1
solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	current_max = 0
	highest = 0
	total = 0
	for i in range(0, n - 1, 2):
		current_max += l[i + 1] - l[i]
		current_max = max(0, current_max)
		highest = max(current_max, highest)
		total += l[i]
	current_max = 0
	for i in range(1, n - 1, 2):
		current_max += l[i] - l[i + 1]
		current_max = max(0, current_max)
		highest = max(current_max, highest)
	if len(l) % 2 == 1:
		total += l[-1]
	print(total + highest)


from copy import deepcopy

def kadane(arr):
	ans = 0
	ansi = 0
	ansj = 0
	present_sum = 0
	present_i = 0
	for i in range(len(arr)):
		present_sum += arr[i]
		if present_sum > ans:
			ans = present_sum
			ansi = present_i
			ansj = i
		if present_sum < 0:
			present_sum = 0
			present_i = i + 1
	return (ans, ansi, ansj)
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	a1 = []
	i = 0
	while i < len(a) - 1:
		a1.append(a[i + 1] - a[i])
		i += 2
	(ans1, i1, j1) = kadane(a1)
	(ans1, i1, j1) = (ans1, i1 * 2, j1 * 2 + 1)
	i = 1
	a1 = []
	while i < len(a) - 1:
		a1.append(a[i] - a[i + 1])
		i += 2
	(ans2, i2, j2) = kadane(a1)
	(ans2, i2, j2) = (ans2, i2 * 2 + 1, j2 * 2 + 2)
	if ans1 > ans2:
		b = a[0:i1]
		c = deepcopy(a[i1:j1 + 1])
		c.reverse()
		b += c
		if j1 < len(a) - 1:
			b += a[j1 + 1:]
	elif ans2 > ans1:
		b = a[0:i2]
		c = deepcopy(a[i2:j2 + 1])
		c.reverse()
		b += c
		if j2 < len(a) - 1:
			b += a[j2 + 1:]
	elif ans1 == ans2:
		if ans1 == 0:
			b = a
		else:
			b = a[0:i2]
			c = deepcopy(a[i2:j2 + 1])
			c.reverse()
			b += c
			if j2 < len(a) - 1:
				b += a[j2 + 1:]
	i = 0
	ans = 0
	while i < len(b):
		ans += b[i]
		i += 2
	print(ans)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	n = getInt()
	a = getList()
	s = 0
	maxZ = 0
	z1 = 0
	z2 = 0
	for i in range(0, n, 2):
		s += a[i]
		if i < n - 1:
			z1 += a[i + 1] - a[i]
		if i > 0:
			z2 += a[i - 1] - a[i]
		z1 = max(z1, 0)
		z2 = max(z2, 0)
		maxZ = max(z1, z2, maxZ)
	print(s + maxZ)


def solve(A):
	n = len(A)
	if n == 0:
		return 0
	assert n & 1 == 0
	B = []
	for i in range(0, n, 2):
		B.append(-A[i] + A[i + 1])
	n = len(B)
	S = [0]
	for b in B:
		S.append(S[-1] + b)
	minn = 0
	best = 0
	for i in range(n):
		minn = min(minn, S[i + 1])
		best = max(best, S[i + 1] - minn)
	return best
t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	if n & 1:
		print(sum(A[::2]) + max(solve(A[1:][::-1]), solve(A[:-1])))
	else:
		print(sum(A[::2]) + max(solve(A), solve(A[1:-1][::-1])))


def sum_even():
	_sum = 0
	for _i in range(0, len(array), 2):
		_sum += array[_i]
	return _sum

def max_sub_sum(_array):
	dp = [0 for _i in range(len(_array))]
	dp[0] = _array[0]
	for _i in range(1, len(_array)):
		dp[_i] = max(_array[_i], dp[_i - 1] + _array[_i])
	result = dp[0]
	for _i in range(1, len(_array)):
		if dp[_i] > result:
			result = dp[_i]
	return result
n_cases = int(input())
for n in range(0, n_cases):
	length = int(input())
	temp = input()
	array = [int(n) for n in temp.split()]
	if length == 1:
		print(array[0])
		continue
	if length == 2:
		print(max(array[0], array[1]))
		continue
	ori_arr = array.copy()
	ori_sum = sum_even()
	diff_left = []
	diff_right = []
	for i in range(0, length - 1, 2):
		diff_left.append(array[i + 1] - array[i])
	for i in range(1, length - 1, 2):
		diff_right.append(array[i] - array[i + 1])
	sum_left = max_sub_sum(diff_left)
	sum_right = max_sub_sum(diff_right)
	if sum_left >= sum_right and sum_left > 0:
		print(ori_sum + sum_left)
	elif sum_right >= sum_left and sum_right > 0:
		print(ori_sum + sum_right)
	else:
		print(ori_sum)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	v1 = []
	v2 = []
	for i in range(1, n, 2):
		v1.append(a[i] - a[i - 1])
	for i in range(2, n, 2):
		v2.append(a[i - 1] - a[i])
	m1 = 0
	m2 = 0
	if v1:
		cm = v1[0]
		m1 = cm
		for i in v1[1:]:
			cm = max(cm + i, i)
			m1 = max(cm, m1)
	if v2:
		cm = v2[0]
		m2 = cm
		for i in v2[1:]:
			cm = max(cm + i, i)
			m2 = max(cm, m2)
	m = max(0, m1, m2)
	print(sum(a[::2]) + m)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n <= 2:
		print(max(a))
	else:
		s = sum(a[::2])
		diff1 = []
		for i in range(1, n, 2):
			diff1.append(a[i] - a[i - 1])
		diff2 = []
		for i in range(2, n, 2):
			diff2.append(a[i - 1] - a[i])
		msf1 = max(diff1[0], 0)
		ans1 = msf1
		for i in range(1, len(diff1)):
			msf1 = diff1[i] + max(0, msf1)
			ans1 = max(msf1, ans1)
		msf2 = max(diff2[0], 0)
		ans2 = msf2
		for i in range(1, len(diff2)):
			msf2 = diff2[i] + max(0, msf2)
			ans2 = max(msf2, ans2)
		print(s + max(ans1, ans2))


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')
from collections import defaultdict as vector
from collections import deque as que
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))

def maxSubArraySum(even, odd, size):
	max_so_far = 0
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += odd[i] - even[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
Testcase = inin()
for _ in range(Testcase):
	n = inin()
	arr = inar()
	ans = 0
	if n % 2:
		n += 1
		arr.append(0)
	even = []
	odd = []
	for i in range(n):
		if i % 2:
			odd.append(arr[i])
		else:
			even.append(arr[i])
			ans += arr[i]
	cpy = ans
	ans += maxSubArraySum(even, odd, len(even))
	odd = [0] + odd[:-1]
	ans = max(ans, cpy + maxSubArraySum(even, odd, len(even)))
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	even_sum = 0
	csum = [0]
	for i in range(n):
		if i % 2 == 0:
			even_sum += a[i]
			csum.append(csum[-1] - a[i])
		else:
			csum.append(csum[-1] + a[i])
	even_add = 0
	odd_add = 0
	for i in range(n + 1):
		if i == 0:
			even_min = csum[i]
			even_add = csum[i]
		elif i == 1:
			odd_min = csum[i]
			odd_add = csum[i]
		if i % 2 == 0:
			even_add = max(even_add, csum[i] - even_min)
			even_min = min(even_min, csum[i])
		else:
			odd_add = max(odd_add, csum[i] - odd_min)
			odd_min = min(odd_min, csum[i])
	ans = even_sum + max(odd_add, even_add, 0)
	print(ans)


def main():
	for i in range(int(input())):
		solve()

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	mseg = 0
	diffs = []
	for i in range(1, n, 2):
		diffs.append(a[i] - a[i - 1])
	m1 = 0
	maxAtP1 = 0
	for i in diffs:
		maxAtP1 = max(maxAtP1 + i, i, 0)
		m1 = max(m1, maxAtP1)
	diffs = []
	for i in range(1, n - 1, 2):
		diffs.append(a[i] - a[i + 1])
	m2 = 0
	maxAtP2 = 0
	for i in diffs:
		maxAtP2 = max(maxAtP2 + i, i, 0)
		m2 = max(m2, maxAtP2)
	ans = max(m1, m2)
	for i in range(0, n, 2):
		ans += a[i]
	print(ans)
main()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	best = 0
	oddMin = 0
	evenMin = 0
	cumulative = 0
	for (i, x) in enumerate(A):
		if i % 2 == 0:
			cumulative -= x
			best = max(best, cumulative - evenMin)
			evenMin = min(evenMin, cumulative)
		else:
			cumulative += x
			best = max(best, cumulative - oddMin)
			oddMin = min(oddMin, cumulative)
	return sum((x for (i, x) in enumerate(A) if i % 2 == 0)) + best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	B1 = []
	B2 = []
	for i in range(N - 1):
		if i % 2 == 0:
			B1.append(A[i + 1] - A[i])
		else:
			B2.append(A[i] - A[i + 1])
	acc1 = [0] + list(accumulate(B1))
	acc2 = [0] + list(accumulate(B2))
	accmn1 = list(accumulate(acc1, min))
	accmx1 = list(accumulate(acc1[::-1], max))[::-1]
	accmn2 = list(accumulate(acc2, min))
	accmx2 = list(accumulate(acc2[::-1], max))[::-1]
	N1 = len(acc1)
	N2 = len(acc2)
	base = sum([a if i % 2 == 0 else 0 for (i, a) in enumerate(A)])
	ans = base
	for i in range(N1 - 1):
		l = accmn1[i]
		r = accmx1[i + 1]
		ans = max(ans, base + r - l)
	for i in range(N2 - 1):
		l = accmn2[i]
		r = accmx2[i + 1]
		ans = max(ans, base + r - l)
	print(ans)


__MULTITEST = True

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = -1
	da = []
	db = []
	for i in range(1, n, 2):
		da.append(a[i] - a[i - 1])
	glMax = 0
	la = 0
	ra = -1
	curMax = 0
	lc = 0
	rc = -1
	for i in range(len(da)):
		curMax += da[i]
		if curMax > 0:
			rc = i
			if curMax > glMax:
				glMax = curMax
				(la, ra) = (lc, rc)
		else:
			curMax = 0
			lc = i + 1
	db = []
	for i in range(2, n, 2):
		db.append(a[i - 1] - a[i])
	glMaxB = 0
	lB = 0
	rB = -1
	curMax = 0
	lc = 0
	rc = -1
	for i in range(len(db)):
		curMax += db[i]
		if curMax > 0:
			rc = i
			if curMax > glMaxB:
				glMaxB = curMax
				(lB, rB) = (lc, rc)
		else:
			curMax = 0
			lc = i + 1
	if glMax < glMaxB:
		l = lB * 2 + 1
		r = rB * 2 + 2
	else:
		l = la * 2
		r = ra * 2 + 1
	a1 = a[:l]
	a2 = a[l:r + 1]
	a2.reverse()
	a3 = a[r + 1:]
	a = a1 + a2 + a3
	print(sum([a[i] for i in range(len(a)) if i % 2 == 0]))
t = int(input()) if __MULTITEST else 1
for tt in range(t):
	solve()


import io
import os
from sys import stdout, stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = 0
	c = 0
	d = []
	for i in range(n):
		if i % 2 == 0:
			b += a[i]
		else:
			c += a[i]
		d.append(c - b)
	ans = 0
	od_min = sum1 = 0
	ev_min = 10 ** 10
	for (ind, val) in enumerate(d):
		if ind % 2 == 0:
			ans = max(ans, val - ev_min)
		else:
			ans = max(ans, val - od_min)
		if ind % 2 == 0:
			ev_min = min(val, ev_min)
		else:
			od_min = min(val, od_min)
	print(ans + b)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ev = 0
	l = []
	m = []
	for i in range(0, n, 2):
		ev += arr[i]
	for i in range(1, n, 2):
		l.append(arr[i] - arr[i - 1])
		if i + 1 < n:
			m.append(arr[i] - arr[i + 1])
	k = len(l)
	ma = -10000000
	cur = 0
	for i in range(k):
		cur = max(l[i], cur + l[i])
		ma = max(ma, cur)
	k = len(m)
	ma2 = -10000000
	cur = 0
	for i in range(k):
		cur = max(m[i], cur + m[i])
		ma2 = max(ma2, cur)
	print(max(ev, ev + max(ma, ma2)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	esum = 0
	for i in range(0, n, 2):
		esum += a[i]
	a_sum = 0
	temp = 0
	for i in range(1, n, 2):
		temp = max(temp + a[i] - a[i - 1], 0)
		a_sum = max(temp, a_sum)
	temp = 0
	for i in range(2, n, 2):
		temp = max(temp + a[i - 1] - a[i], 0)
		a_sum = max(temp, a_sum)
	print(esum + a_sum)


def subs(lst):
	curr_max = 0
	global_max = 0
	for i in lst:
		curr_max = max(i, curr_max + i)
		global_max = max(global_max, curr_max)
	return global_max

def solve(lst):
	evens = []
	odds = []
	length = len(lst)
	for i in range(length):
		if i % 2 == 0:
			evens.append(lst[i])
		else:
			odds.append(lst[i])
	diff = []
	diff2 = []
	for i in range(len(odds)):
		try:
			diff.append(odds[i] - evens[i])
			diff2.append(odds[i] - evens[i + 1])
		except IndexError:
			pass
	sub1 = subs(diff)
	sub2 = subs(diff2)
	excess = max(sub1, sub2)
	return sum(evens) + excess
test = int(input())
matrix = []
for _ in range(test):
	length = int(input())
	lst = list(map(lambda elem: int(elem), input().split(' ')))
	matrix.append(lst)
for lst in matrix:
	print(solve(lst))


import math

def maxSubArraySum(a, size):
	max_so_far = -math.inf - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
for ii in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	su = 0
	l1 = [a[i + 1] - a[i] for i in range(0, n - n % 2, 2)]
	l2 = [a[i] - a[i + 1] for i in range(1, n - 1 + n % 2, 2)]
	for i in range(n):
		if i % 2 == 0:
			su += a[i]
	c = maxSubArraySum(l1, len(l1))
	d = maxSubArraySum(l2, len(l2))
	x = max(c, d)
	if x < 0:
		print(su)
	else:
		print(su + x)


for I in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
	else:
		prev = 0
		for (i, num) in enumerate(a):
			if i % 2 == 0:
				prev += num
		resulting = [0]
		resulting.append(max(0, a[1] - a[0]))
		for i in range(1, n - 1):
			if i % 2 == 0:
				temp = a[i + 1] - a[i]
				temp += resulting[i - 1]
			else:
				temp = a[i] - a[i + 1]
				temp += resulting[i - 1]
			resulting.append(max(0, temp))
		print(prev + max(resulting))


t = int(input())

def forward_pass(x):
	n_a = [x[i + 1] - x[i] for i in range(0, len(x) - 1, 2)]
	m = 0
	c = 0
	for n in n_a:
		c += n
		if c < 0:
			c = 0
		m = max(m, c)
	return m
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	ans = sum([x for (i, x) in enumerate(a) if i % 2 == 0])
	if len(a) % 2 == 0:
		rev = a[:-1]
	else:
		rev = a
	ans += max(forward_pass(a), forward_pass(rev[::-1]))
	print(ans)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	arr = iia()
	(num1, num2) = ([], [])
	tot1 = tot2 = 0
	for i in range(0, len(arr), 2):
		tot1 += arr[i]
		if i < len(arr) - 1:
			num1.append(arr[i + 1] - arr[i])
	for i in range(1, len(arr), 2):
		if i < len(arr) - 1:
			num2.append(arr[i] - arr[i + 1])
	cur = big = 0
	for i in range(len(num1)):
		cur = max(num1[i], cur + num1[i])
		big = max(big, cur)
	tot2 = tot1
	tot1 += big
	cur = big = 0
	for i in range(len(num2)):
		cur = max(num2[i], cur + num2[i])
		big = max(big, cur)
	tot2 += big
	print(max(tot1, tot2))


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	if n == 1:
		print(b[0])
	elif n == 2:
		print(max(b[0], b[1]))
	else:
		j = 0
		res = 0
		while j < n:
			if j % 2 == 0:
				res += b[j]
			j += 1
		r1 = 0
		r2 = 0
		j = 1
		p = 0
		q = 0
		while j < n:
			if j % 2 != 0:
				s = b[j] - b[j - 1]
				r1 = max(s, r1 + s)
				p = max(p, r1)
			else:
				s = b[j - 1] - b[j]
				r2 = max(s, r2 + s)
				q = max(q, r2)
			j += 1
		res += max(0, p, q)
		print(res)


import sys
input = sys.stdin.readline
from math import ceil
answer = []
for kek in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			ans += a[i]
	for i in range(0, n - 1, 2):
		b.append(a[i + 1] - a[i])
	for i in range(1, n - 1, 2):
		c.append(a[i] - a[i + 1])
	x = 0
	s = 0
	for i in b:
		s += i
		if s < 0:
			s = 0
		else:
			x = max(x, s)
	x = max(x, s)
	s = 0
	for i in c:
		s += i
		if s < 0:
			s = 0
		else:
			x = max(x, s)
	x = max(x, s)
	ans += x
	answer.append(ans)
print(*answer, sep='\n')


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		print(f(n, a))

def f(n, a):
	odd_sum = 0
	for i in range(0, n, 2):
		odd_sum += a[i]
	prefix = 0
	min_prefix_even = 0
	min_prefix_odd = float('inf')
	max_shift = 0
	for i in range(n):
		if i % 2 == 0:
			prefix -= a[i]
		else:
			prefix += a[i]
		if i % 2 == 1:
			max_shift = max(max_shift, prefix - min_prefix_even)
			min_prefix_even = min(min_prefix_even, prefix)
		else:
			max_shift = max(max_shift, prefix - min_prefix_odd)
			min_prefix_odd = min(min_prefix_odd, prefix)
	return max(odd_sum, odd_sum + max_shift)
main()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	for i in range(1, n, 2):
		b[i] = a[i] - a[i - 1]
	mx = 0
	curr = 0
	for i in range(n):
		curr += b[i]
		mx = max(mx, curr)
		if curr < 0:
			curr = 0
	r = mx
	b = [0] * n
	for i in range(1, n - 1, 2):
		b[i] = a[i] - a[i + 1]
	mx = 0
	curr = 0
	for i in range(n):
		curr += b[i]
		mx = max(mx, curr)
		if curr < 0:
			curr = 0
	r = max(mx, r)
	for i in range(n):
		if i % 2 == 0:
			r += a[i]
	print(r)


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	if n == 1:
		stdout.write(str(a[0]) + '\n')
	else:
		prefix = [0] * n
		count = 0
		for x in range(n):
			if x % 2 == 0:
				count -= a[x]
			else:
				count += a[x]
			prefix[x] = count
		prefix.insert(0, 0)
		minevens = [0] * (n + 1)
		minimum = a[0]
		for x in range(0, n + 1, 2):
			minimum = min(minimum, prefix[x])
			minevens[x] = minimum
		minodds = [0] * (n + 1)
		minimum = a[1]
		for x in range(1, n + 1, 2):
			minimum = min(minimum, prefix[x])
			minodds[x] = minimum
		maximum = 0
		for x in range(1, n + 1, 2):
			maximum = max(maximum, prefix[x] - minodds[x])
		count = 0
		for x in range(0, n + 1, 2):
			maximum = max(maximum, prefix[x] - minevens[x])
			if x <= n - 1:
				count += a[x]
		stdout.write(str(count + maximum) + '\n')


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	s = sum(lis[::2])
	arr = [0] * (n // 2)
	for i in range(1, n, 2):
		arr[i // 2] = lis[i] - lis[i - 1]
	m1 = 0
	l = 0
	for i in range(len(arr)):
		l += arr[i]
		m1 = max(l, m1)
		l = max(l, 0)
	arr = [0] * ((n - 1) // 2)
	for i in range(2, n, 2):
		arr[(i - 1) // 2] = lis[i - 1] - lis[i]
	m2 = 0
	l = 0
	for i in range(len(arr)):
		l += arr[i]
		m2 = max(l, m2)
		l = max(l, 0)
	print(s + max(m1, m2))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	current_diff = 0
	max_diff = 0
	for i in range(0, n, 2):
		if i + 1 < len(a):
			current_diff += a[i + 1] - a[i]
			if current_diff > max_diff:
				max_diff = current_diff
			if current_diff < 0:
				current_diff = 0
	current_diff = 0
	for i in range(1, n, 2):
		if i + 1 < len(a):
			current_diff += a[i] - a[i + 1]
			if current_diff > max_diff:
				max_diff = current_diff
			if current_diff < 0:
				current_diff = 0
	s = 0
	for i in range(0, len(a), 2):
		s += a[i]
	print(s + max_diff)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	o = 0
	e = 0
	oe = []
	for i in range(n):
		if i & 1:
			o += a[i]
		else:
			e += a[i]
		oe.append(o - e)
	om = int(1000000000000000.0)
	em = int(1000000000000000.0)
	ma = -int(1000000000000000.0)
	for i in range(n):
		if i & 1:
			ma = max(oe[i], oe[i] - om, ma)
			om = min(oe[i], om)
		else:
			ma = max(oe[i] - em, ma)
			em = min(oe[i], em)
	print(max(e, e + ma))


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()

def kadane(a):
	cs = 0
	gs = 0
	for i in a:
		cs += i
		cs = max(cs, i)
		gs = max(cs, gs)
	return gs
for _ in range(int(inp())):
	n = int(inp())
	a = list(map(int, inp().split()))
	eve = 0
	for i in range(n):
		if i % 2 == 0:
			eve += a[i]
	b = []
	c = []
	for i in range(1, n - 1, 2):
		b.append(a[i] - a[i + 1])
	for i in range(0, n - 1, 2):
		c.append(a[i + 1] - a[i])
	print(max(kadane(b), kadane(c)) + eve)


def max_subarray(a):
	local_max = 0
	global_max = float('-inf')
	for i in range(len(a)):
		local_max = max(a[i], a[i] + local_max)
		if local_max > global_max:
			global_max = local_max
	return global_max
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	first_arr = [a[2 * i + 1] - a[2 * i] for i in range(n // 2)]
	first_max = max_subarray(first_arr)
	second_arr = [a[2 * i + 1] - a[2 * i + 2] for i in range((n - 1) // 2)]
	second_max = max_subarray(second_arr)
	ans = sum(a[::2]) + max(first_max, second_max, 0)
	print(ans)


from sys import stdin
A = int(stdin.readline())
for u in range(0, A):
	B = int(stdin.readline())
	C = list(map(int, stdin.readline().split()))
	even = 0
	A = list()
	D = list()
	switch = 0
	odd = 0
	for y in range(0, len(C)):
		if y % 2 == 0:
			even += C[y]
		if y % 2 == 1:
			odd += C[y]
		if y < len(C) - 1:
			if switch == 0:
				A.append(C[y + 1] - C[y])
				switch = 1
			else:
				D.append(C[y] - C[y + 1])
				switch = 0
	MAX = 0
	temp = 0
	for r in A:
		temp += r
		MAX = max(MAX, temp, r)
		if temp < 0:
			temp = 0
	temp = 0
	for r in D:
		temp += r
		MAX = max(MAX, temp, r)
		if temp < 0:
			temp = 0
	print(max(even + MAX, odd))


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def ad(asa):
	ans = 0
	if bool(asa):
		ans = asa[0]
		summ = 0
		min_sum = 0
		for r in range(len(asa)):
			summ += asa[r]
			ans = max(ans, summ - min_sum)
			min_sum = min(min_sum, summ)
	return ans

def solve():
	n = int(ii())
	data = idata()
	if n == 1:
		print(data[0])
		return
	ans = 0
	for i in range(0, n, 2):
		ans += data[i]
	sp1 = []
	sp2 = []
	for i in range(0, n - 1, 2):
		sp1 += [data[i + 1] - data[i]]
		if i + 2 != n:
			sp2 += [data[i + 1] - data[i + 2]]
	print(max(ans, ans + ad(sp1), ans + ad(sp2)))
	return
for t in range(int(ii())):
	solve()


def f(s, neg):
	t = []
	for i in range(0, len(s), 2):
		t.append((s[i] - s[i + 1]) * neg)
	MAX = SUM = 0
	for x in t:
		SUM += x
		if SUM < 0:
			SUM = 0
		MAX = max(SUM, MAX)
	return MAX
for _ in range(int(input())):
	input()
	s = list(map(int, input().split()))
	mod = len(s) % 2
	MAX = max(f(s[:len(s) - mod], -1), f(s[1:len(s) - int(not mod)], 1))
	ans = sum(s[::2]) + MAX
	print(ans)


def maxSubArraySum(a, size):
	max_so_far = -99999999999999999
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
t = int(input())
while t:
	t += -1
	n = int(input())
	l = list(map(int, input().split()))
	a1 = []
	a2 = []
	tp = 0
	for i in range(0, n, 2):
		tp += l[i]
		if i + 1 < n:
			a1.append(l[i + 1] - l[i])
	for i in range(1, n, 2):
		if i + 1 < n:
			a2.append(l[i] - l[i + 1])
	tmp = max(maxSubArraySum(a1, len(a1)), maxSubArraySum(a2, len(a2)))
	print(max(tp, tp + tmp))


def max_subarray(numbers):
	best_sum = 0
	best_start = best_end = 0
	current_sum = 0
	for (current_end, x) in enumerate(numbers):
		if current_sum <= 0:
			current_start = current_end
			current_sum = x
		else:
			current_sum += x
		if current_sum > best_sum:
			best_sum = current_sum
			best_start = current_start
			best_end = current_end + 1
	return (best_sum, best_start, best_end)

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	b = []
	c = []
	s = 0
	for i in range(n):
		if i % 2 == 0:
			if i + 1 < n:
				b.append(a[i + 1] - a[i])
			s += a[i]
		elif i + 1 < n:
			c.append(a[i] - a[i + 1])
	(p, q, r) = max_subarray(b)
	(p1, q1, r1) = max_subarray(c)
	print(s + max(p, p1))
t = int(input())
for i in range(t):
	solve()


def qwerty(asa):
	ans = 0
	if bool(asa):
		ans = asa[0]
		summ = 0
		min_sum = 0
		for r in range(len(asa)):
			summ += asa[r]
			ans = max(ans, summ - min_sum)
			min_sum = min(min_sum, summ)
	return ans
for t in range(int(input())):
	n = int(input())
	data = [int(x) for x in input().split()]
	ans = 0
	if n == 1:
		print(data[0])
		continue
	for i in range(0, n, 2):
		ans += data[i]
	sp1 = []
	sp2 = []
	for i in range(0, n - 1, 2):
		sp1 += [data[i + 1] - data[i]]
		if i + 2 != n:
			sp2 += [data[i + 1] - data[i + 2]]
	print(max(ans, ans + qwerty(sp1), ans + qwerty(sp2)))


for tt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1 or n == 2:
		print(max(a))
		continue
	ans = 0
	for s in range(2):
		suff = (s == 0 and n % 2) * a[-1]
		for i in range(s, n - (n - s) % 2, 2):
			suff += a[i + s]
		pref = s * a[0]
		ans = max(ans, pref + suff)
		cur = 0
		for i in range(s, n - (n - s) % 2, 2):
			suff -= a[i + s]
			cur = max(cur, pref + a[i + (s ^ 1)], cur + a[i + (s ^ 1)])
			pref += a[i + s]
			ans = max(ans, max(pref, cur) + suff)
	print(ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def instr():
	return str(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(map(int, list(s[:len(s) - 1])))

def invr():
	return map(int, input().split())
from collections import Counter

def handle(odd, even):
	res = 0
	max_res = 0
	for (o, e) in zip(odd, even):
		res += o - e
		if res > max_res:
			max_res = res
		if res < 0:
			res = 0
	return max_res

def main():
	t = inp()
	for _ in range(t):
		n = inp()
		a = inlt()
		odd = a[1::2]
		even = a[::2]
		even_sum = sum(even)
		res = max(handle(odd, even), handle(odd, even[1:]))
		res += even_sum
		print(res)
main()