#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

bool solve(const auto& balls) {
    const int n = balls.size();
    stack<int> l, r;
    
    function<bool(int)> rec = [&](int i) {
        if (i == n) return true;

        bool pro = false;
        if (l.empty() || l.top() < balls[i]) { // left push
            l.push(balls[i]);
            pro = pro || rec(i + 1);
            l.pop();
        } 

        if (r.empty() || r.top() < balls[i]) { // right push
            r.push(balls[i]);
            pro = pro || rec(i + 1);
            r.pop();
        }

        return pro;
    };

    return rec(0);
}

int main() {
    constexpr int BALLS = 10;
    int n; cin >> n;
    REP(i, n) {
        vector<int> b(BALLS);
        REP(j, BALLS) cin >> b[j];

        if (solve(b)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

