/** * 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); rep(i,n) cin >> a[i]; ll ans = 0; rep(i,3){ vector dp(n+1); rep(j,n){ dp[j+1]=max(dp[j+1],dp[j]); if(j+3