#include <iostream>
#include <vector>
using namespace std;

int main(void){
  int N,temp,flag;
  vector<int> A,B(1,0),C(1,0);
  cin >> N;
  for(int i=0; i<N; ++i){
    for(int j=0; j<10; ++j){
	cin >> temp;
	A.push_back(temp);
      }
    while(!A.empty()){
      temp = A.front();
      if(temp>=B.back()) B.push_back(temp);
      else if(temp>=C.back()) C.push_back(temp);
      else{
	cout << "NO" << endl;
	flag = 1;
	break;
      }
      A.erase(A.begin());
    }
    if(flag!=1)
      cout << "YES" << endl;
    flag=0;
    A.clear(); B.clear(); C.clear();
  }
}
      