#include <iostream>

using namespace std;

int main(void){
  int data;
  int data_set;
  int box1,box2;
  int i,j,k,l;
  bool f;

  cin>>data_set;
  for(i=0;i<data_set;i++){
    box1=0;
    box2=0;
    f=false;
    for(j=0;j<10;j++){
      cin>>data;
      if(data>box1&&data>box2){
	if(box1<box2){
	  box2=data;
	}else{
	  box1=data;
	}
      }
      else if(data>box1){
	box1=data;
      }
      else if(data>box2){
	box2=data;
      }
      else{
	f=true;
      }
    }
    if(f){
      cout<<"NO"<<endl;
    }else{
      cout<<"YES"<<endl;
    }
  }
  return(0);
}