#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main () {
    int b[10];
    int l=0,r=0;

    int x;
    cin>>x;
    
    while(cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9]){
        int flag=0;
        for(int i=0; i<10; i++){
            if(l<b[i]&&r<b[i]){
                if(l<r){
                    r=b[i];
                }else{
                    l=b[i];
                }
            }else if(l>b[i]&&r<b[i]){
                r=b[i];
            }else if(l<b[i]&&r>b[i]){
                l=b[i];
            }else{
                flag++;;
                break;
            }
        }
        
        if(flag){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }

    }
    return 0;
}