#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
vector<int> a;
vector<int> b;
int v[10];
bool dfs(int);

int main(){
    int n;
    cin>>n;
    while(n>0){
        rep(i,10){
            cin>>v[i];
        }
        a.erase(all(a));
        b.erase(all(b));
        if(dfs(0)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        n--;
    }
    return 0;
}

bool dfs(int i){
    if(i==10) return true;
    vector<int>::iterator itr;
    if(a.size()>0){
        itr= a.end();
        if(v[i]>*itr){
            a.pb(v[i]);
            if(dfs(i+1)) return true;
            a.pop_back();
        }
    }else{
        a.pb(v[i]);
        if(dfs(i+1)) return true;
        a.pop_back();
    }
    if(b.size()>0){
        itr= b.end();
        if(v[i]>*itr){
            b.pb(v[i]);
            if(dfs(i+1)) return true;
            b.pop_back();
        }
    }else{
        b.pb(v[i]);
        if(dfs(i+1)) return true;
        b.pop_back();
    }
    if(i>0){
        vector<int>::iterator itr2;
        itr= a.end();
        itr2= b.end();
        if(v[i]<=*itr && v[i]<=*itr2)return false;
    }
    return false;
}

