#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 10;

bool dfs(vector<int> a, vector<int> b, vector<int> vec, int now){
    if(now >= N) return true;
    else{
        bool ret = false;
        if(a.size() == 0 || vec[now] > a[a.size() - 1]){
            vector<int> tmp = a;
            tmp.push_back(vec[now]);
            ret = max(ret, dfs(tmp, b, vec, now + 1));
        }
        if(b.size() == 0 || vec[now] > b[b.size() - 1]){
            vector<int> tmp = b;
            tmp.push_back(vec[now]);
            ret = max(ret, dfs(a, tmp, vec, now + 1));
        }
        return ret;
    }
}


int main(){
    int n; cin >>n;
    REP(z, n){
        vector<int> vec(N); REP(i, N) cin >>vec[i];
        cout <<((dfs(vector<int>(), vector<int>(), vec, 0))? "YES" : "NO") <<endl;
    }
    return 0;
}