#include<iostream>
using namespace std;

int l,r,x,ball[11],le[11],ri[11],ans,n;
int dfs(int i,int l,int r){
    if(i > 9){
        return ans=1;
    }
    if(le[l]<ball[i]){
        le[++l]=ball[i++];
        dfs(i,l,r);
    }
    else if(ri[r]<ball[i]){
        ri[++r]=ball[i++];
         dfs(i,l,r);
    }
    else
        ans=0;
}
void solve(){
    cin>>n;
    while(n--){
        
        for(int j = 0;j < 10;j++)
            cin>>ball[i];
        ans= 0;
        dfs(0,0,0);
        if(ans)
            cout>>"YES">>endl;
        else
            cout>>"NO">>endl;
        
    }
}


