#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

#define REP(i,n) for ( int i = 0; i < (int)n; i++ )
#define FOR(i,c) for ( __typeof((c).begin())i=(c).begin(); i != (c).end(); i++ )
#define ALL(c) (c).begin(), (c).end()

typedef vector <int> VI;
int a, b;

bool solve( VI L, int d ) {
  if ( d >= (int)L.size() ) {
    return true;
  }
  int ba = a;
  int bb = b;
  if ( L[d] > a ) {
    a = L[d];
    if ( solve( L, d + 1 ) ) return true;
    a = ba;
  }
  if ( L[d] > b ) {
    b = L[d];
    if ( solve( L, d + 1 ) ) return true;
    b = bb;
  }
  return false;
}

int main() {
  int n;
  while ( cin >> n ) {
    for ( int i = 0; i < n; ++ i ) {
      VI L( 10 );
      for ( int j = 0; j < 10; ++ j ) {
	cin >> L[j];
      }
      a = 0;
      b = 0;
      cout << ( solve( L, 0 ) ? "YES" : "NO" ) << endl;
    }
  }
  return 0;
}