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