def is_kadomatsu(a,b,c): if a==b or b==c or a==c or a+b+c-max(a,b,c)-min(a,b,c)==b: return False return True def solve(a,start,n): dp = [0]*(n+1) for i in range(n): dp[i+1] = max(dp[i+1],dp[i]) idx = i+start if i+3 <= n and is_kadomatsu(*a[idx:idx+3]): dp[i+3] = max(dp[i+3],dp[i]+a[idx]) return dp[-1] T = int(input()) for _ in range(T): n = int(input()) *a, = map(int,input().split()) a += a[:2] ans = max(solve(a,0,n),solve(a,1,n),solve(a,2,n)) print(ans)