#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-30;
constexpr double PI = atan(1) * 4;

template <class T> inline void chmax(T& x, T y) {if (x < y) x = y;}
template <class T> inline void chmin(T& x, T y) {if (x > y) x = y;}
inline int LSB(int i) {return (i & -i);}

int t, n, a[3000], dp[3000];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> t;
    while (t--){
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i];
        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= n; i++){
            for (int j = 1; j < i; j++){
                if (a[j] <= a[i]) chmax(dp[i], dp[j] + 1);
            }
        }
        
        if (*max_element(dp + 1, dp + n + 1) >= n - 2) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}