#include <iostream>

#define MAX 10
using namespace std;

bool can_stack(int,int,int);

int main(){
  int count;
  int ball1,ball2,ball;
  cin >> count;
  for(int i=0;i<count;i++){
    ball1=0;ball2=0;
    for(int j=0;j<MAX;j++){
      cin >>ball;
      //      cout << ball << endl;
      if(!can_stack(ball1,ball2,ball)){
	cout << "NO";
	break;
      }
      else{
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
    }
    if(i!=count-1){
      cout << endl;
    }
  }
}

bool can_stack(int ball1,int ball2,int ball){
  return (ball1<ball || ball2 < ball);
}