#!/usr/bin/env python3
#coding:utf-8

import math
import string
from sys import stdin
# import numpy as np
# from matplotlib import pyplot as plt

	
def main():
	read=stdin.readline

	#edit here!
	t=int(read())
	while t>0:
		t-=1
		n=int(read())
		a=list(map(int,read().split()))

		check=lambda a,b,c:a!=b and b!=c and c!=a and (a<b>c or a>b<c)
		res=0
		ans=0
		i=0
		while i<n-2:
			
			if check (a[i],a[i+1],a[i+2]):
				ans+=a[i]
				i+=3
			else :
				i+=1
		
		i=0
		while i<n-2:
			if check(a[(i+1)%n],a[(i+2)%n],a[(i+3)%n]):
				res+=a[(i+1)%n]
				i+=3
			else:
				i+=1

		ans=max(ans,res)
		res=0
		
		i=0
		while i<n-2:
			if check(a[(i+2)%n],a[(i+3)%n],a[(i+4)%n]):
				res+=a[(i+2)%n]
				i+=3
			else:
				i+=1
		
		ans=max(ans,res)
		print(ans)

if __name__ == '__main__':
	main()