#include <iostream>

#define MAX 10
using namespace std;

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 << ball1 << " " << ball2 << endl;
      //      cout << ball << endl;
      //cout << j << endl;
      if(ball1 < ball || ball2 < ball){
	if(ball2<ball){
	  ball2=ball;
	}
	else{
	  ball1 = ball;
	}
	if(j==MAX-1){
	  cout << "YES";
	}
      }
      else{
	cout << "NO";
	for(int k=0;k<MAX-j;k++) cin >>ball;
	break;
      }
    }
    cout << endl;
  }
}