#include<iostream>
using namespace std;
int main(){
  int n,ball,a=0,b=0;
  cin >> n;
  for(int i=0;i<n;i++){
    int flg = 0;
    for(int i=0;i<10;i++){
      cin >> ball;
      if(a < ball){
	a = ball;
      } else if(b < ball){
	b = ball;
      } else{
	flg = 1;
      }
    }
    if(flg == 0){
      cout <<"YES" << endl;
    } else{
      cout << "NO" << endl;
    }
  }
  return (0);
}