#include<iostream>
using namespace std;
int main(){
  int ball[10],bal[10],n,a,flg;
  cin>>n;
  for(int i=0;i<n;i++){
    flg=0;
    for(int j=0;j<10;j++){
      ball[i]=0;
      bal[i]=0;
    }
    for(int k=0;k<10;k++){
      cin>>a;
      if(ball[i]<a){
	ball[i]=a;
      }else if(bal[i]<a){
	bal[i]=a;
      }else{
	flg=1;
      }
    }
    if(flg==0){
      cout<<"YES"<<endl;
    }if(flg==1){
      cout<<"NO"<<endl;
    }
  }
  return 0;
}

	       