#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <functional>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-10;

bool dfs(int* a, vector<int> &b, vector<int> &c, int n) {
    if(n == 10) return true;

    bool ok = false;
    if(b.empty() || b.back() < a[n]) {
        b.push_back(a[n]);
        ok |= dfs(a, b, c, n+1);
        b.pop_back();
    }
    if(c.empty() || c.back() < a[n]) {
        c.push_back(a[n]);
        ok |= dfs(a, b, c, n+1);
        c.pop_back();
    }
    return ok;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    int a[10];
    REP(i,N) {
        REP(j,10) cin >> a[j];
        vector<int> b, c;
        if(dfs(a, b, c, 0)) cout << "YES";
        else cout << "NO";
        cout << '\n';
    }
    return 0;
}
