#include <iostream>
using namespace std;
int b[10];
int bt, ct, tmp;
bool check(int i){
  if( i==10 )
    return true;

  if( bt<b[i] ){
    tmp=bt; bt=b[i];
    if( check(i+1) )
      return true;
    bt=tmp;
  }
  if( ct<b[i] ){
    tmp=ct; ct=b[i];
    if( check(i+1) )
      return true;
    ct=tmp;
  }
  return false;
}

int main(){
  int n;
  cin >> n;
  for( int lp=0;lp<n;lp++ ){
    for( int i=0;i<10;i++ )
      cin >> b[i];

    bt=-1, ct=-1;
    if( check(0) )
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}