#include<iostream>
using namespace std;
int main(void)
{
    int bo[11],n,B[11],C[11],b1=0,c1=0,A=0,k=0,l=1;
    cin>>n;
    for(int i=0;i<n;i++){
            C[0]=11;k=0;l=0;B[0]=0;b1=0;c1=0;C[1]=13;
        for(int j=0;j<10;j++){
                //srand(time(NULL));
           cin>>bo[j];
           /*bo[j]=6-5+rand()%10;
            for(int m=0;m<j;m++){
                if(bo[j]==bo[m]){
                    --j;break;
                }
            }*/
        }
        for(int j=0;j<10;j++)cout<<bo[j]<<" ";
        cout<<"\n";
        for(int j=1;;j++){
                cout<<bo[j]<<" ";
            if(j==1)B[0]=bo[0];
        if(C[0]==11&&j==2){
            C[0]=bo[j];
            k++;
           // cout<<"6\n";
        }else if(C[1]==13&&j>3&&C[0]<bo[j]){
            C[1]=bo[j];
            k++;
            c1=1;
            //cout<<"7\n";
        }else if(B[l]<bo[j]){
            b1=1;
            B[l+1]=bo[l];
            l++;
            //cout<<"1\n";
        }else if(C[0]==11){
            C[0]=bo[j];
            k++;
            //cout<<"2\n";
        }else if(C[k-1]<bo[j]){
            c1=1;
            C[k+1]=bo[j];
            //cout<<"3\n";
        }else if(B[l]<bo[j+1]){
            C[k+1]=bo[j];
            k++;
            if(C[k]>C[k-1])c1=1;
            //cout<<"5\n";
        }else if(C[1]==13&&j>3){
            C[1]=bo[j];
            k++;
           // cout<<"7\n";
        }else{
            B[l+1]=bo[j];
            l++;
           // cout<<"4\n";
        }
        if(j==9||(b1==1&&c1==1))break;
    }
    if(b1==1&&c1==1)cout<<"YES\n";
    else cout<<"NO\n";
    for(int j=0;j<10;j++){
        B[j]=0;C[j]=0;
    }

}
}