#include <iostream>

using namespace std;

int main(void){

  int a;
  int b[10] = {0};
  int c[10] = {0};
  int out[10] = {0};

  int n;
  cin >> n;
  while(n--){

    for( int l = 10 ; l > 0 ; l-- ){
    cin >> a;
    int i = 0;
    int j = 0;
    int k = 0;
    if( b[i] < a ){
    b[i++] = a;
    }
    else if( c[j] < a ){
	c[j++] = a;
      }
    else out[k++] = a;
    }
    if( out[0] == 0 )cout << "YES" << endl;
    else cout << "NO" << endl;
  }
 return 0;
}