#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> minvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v1;
  }else{
	return v2;
  }
}

vector<int> maxvec(vector<int> v1, vector<int> v2){
  if(v1.back() < v2.back()){
	return v2;
  }else{
	return v1;
  }
}

int main(void){
  int n;
  int i,j;
  vector<int> q;
  //vector<int> out[2];
  int tmp;
  bool isok = true;
  int a=0, b=0;
  cin >> n;
  for(i=0;i<n;i++){
	for(j=0;j<10;j++){
	  cin >> tmp;
	  q.push_back(tmp);
	}

	for(j=0;j<10;j++){
	  if(q[j] > max(a, b)){
		max(a,b) == a ? a = q[j] : b = q[j];
	  }else if(q[j] < min(a,b)){
		cout << "NO" << endl;
		isok = false;
		break;
	  }else{
		min(a,b) == a ? a = q[j] : b = q[j];
	  }
	}

	if(isok) cout << "YES" << endl;
	isok = true;
	q.clear();
	a = 0; b = 0;
  }
  return 0;
}