#include<iostream>
#include<stack>
#include<map>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    int a[10],x=0,y=0;
    stack<pair<int,int> > log;
    for(int i=0; i<10; i++) cin >>a[i];
    for(int i=0; i<10; i++){
      if(x>a[i] && y<a[i]) y = a[i];
      else if(x<a[i] && y>a[i]) x = a[i];
      else if(x<a[i] && y<a[i]){
	log.push(make_pair(x,i));
	x = a[i];
      }
      else if(x>a[i] && y>a[i]){
	if(log.empty()){
	  cout <<"NO"<<endl;
	  break;
	}
	x = log.top().first;
	i = log.top().second;
	y = a[i];
	log.pop();
      }
      if(i == 9) cout <<"YES"<<endl;
    }
  }
  return 0;
}