#include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int lot[10],save[100][2]={0},tag=0,a,b;
    bool f = true;
    for(int i=0; i<10; i++) cin >>lot[i];
    a = lot[0];
    b = 0;
    for(int i=1; i<10; i++){
      if(a<lot[i] && b>lot[i]) a = lot[i];
      else if(a>lot[i] && b<lot[i]) b = lot[i];
      else if(a<lot[i] && b<lot[i]){
	save[tag][0] = a;
	save[tag][1] = i;
	a = lot[i];
	tag++;
      }
      else if(a>lot[i] && b>lot[i]){
	if(tag == 0){
	  f = false;
	  break;
	}
	else{
	  a = save[tag-1][0];
	  i = save[tag-1][1];
	  b = lot[i];
	  tag--;
	}
      }
    }
    if(f) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
  return 0;
}