#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n;
vector<int> v;

void showVector( vector<int> vec ){
  for( int i = 0; i < vec.size(); i++ ) printf("%d: %d, ", i, vec.at(i));
  cout << endl;
}

bool follow( vector<int> v1 ){
  vector<int> v2;
  for(int i=0; i <  v1.size(); i++ ) v2.push_back( v1.at(i) );
  sort( v2.begin(), v2.end() );
  return v1 == v2;
}

bool dfs( int i, vector<int> l, vector<int> r ){
  if( i == 10 ){ 
    return follow(l) && follow(r);
  }

  vector<int> l2 = l;
  l2.push_back( v.at(i) );
  if( dfs( i + 1, l2, r ) ) return true;

  vector<int> r2 = r;
  r2.push_back( v.at(i) );
  if( dfs( i + 1, l, r2 ) ) return true;
  
  return false;
}

main(){
  vector<int> l, r;
  int tmp;
  cin >> n;
  for( int i=0; i < n; i++ ){
    v.clear();
    for( int j = 0; j < 10; j++ ){
      cin >> tmp;
      v.push_back( tmp );
    }
    if( dfs(0, l, r) ) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}