/** * author: shu8Cream * created: 29.01.2021 20:56:35 **/ #include using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair; using vi = vector; using vvi = vector; bool isKM(vector a){ if(a[0]==a[1] || a[1]==a[2] || a[2]==a[0]) return false; if(max({a[0],a[1],a[2]})==a[1] || min({a[0],a[1],a[2]})==a[1]){ return true; } return false; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; while(t--){ int n; cin >> n; vector a(n+2); rep(i,n) cin >> a[i]; a[n]=a[0]; a[n+1]=a[1]; ll ans = 0; rep(i,3){ ll tmp = 0; for(int j=i; j b(3); b[0]=a[j]; b[1]=a[j+1], b[2]=a[j+2]; if(isKM(b)) tmp+=a[j]; } ans=max(ans, tmp); } cout << ans << endl; } }