#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;

int T;
int mapp[15];

bool dfs(int index,int L,int R){


    if(index==10)return true;

    bool flag=false;

    if(L<mapp[index])   flag=(flag||dfs(index+1,mapp[index],R));
    if(R<mapp[index])   flag=(flag||dfs(index+1,L,mapp[index]));
    return flag;
}


int main(){
    cin>>T;
    while(T--){
        for(int i=0;i<10;i++){
            scanf("%d",&mapp[i]);
        }

        if(dfs(0,0,0)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
        memset(mapp,0,sizeof(mapp));
    }
    return 0;
}

