/** * 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(ll a, ll b, ll c){ if(a==b || b==c || c==a) return false; if(max({a,b,c})==b || min({a,b,c})==b){ 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