import sys input = sys.stdin.readline from collections import * def calc(A): dp = [0]*(N+1) for i in range(2, N): dp[i+1] = dp[i] if len({A[i-2], A[i-1], A[i]})==3: dp[i+1] = max(dp[i+1], dp[i-2]+A[i-2]) return dp[N] for _ in range(int(input())): N = int(input()) A = deque(list(map(int, input().split()))) ans = calc(A) A.append(A.popleft()) ans = max(ans, calc(A)) A.append(A.popleft()) ans = max(ans, calc(A)) print(ans)