#include<iostream>
#include<stack>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  int a[n][10];
  REP(i,n){
    REP(j,10){
      int b;
      cin >> b;
      a[i][j] = b;
    }
  }
  int flag[n] = {0};
  REP(i,n){
    stack <int> b;
    stack <int> c;
    b.push(a[i][0]);
    for(int j = 1;j < 10;j++){
      if(b.top() < a[i][j]){
	b.push(a[i][j]);
      }
      else{
	if(c.empty()){
	  c.push(a[i][j]);
	}
	else if(c.top() < a[i][j]){
	  c.push(a[i][j]);
	}
	else{
	  flag[i] = 1;
	}
      }
    }
  }

  REP(i,n){
    if(flag[i] == 1){
      cout << "NO" << endl;
    }
    else{
      cout << "YES" << endl;
    }
  }

}