#include <iostream>
#include <vector>
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;;
  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(out[0].empty()){
		out[0].push_back(q[j]);
	  }else if(out[1].empty()){
		out[1].push_back(q[j]);
	  }else if(q[j] > maxvec(out[0], out[1]).back()){
		maxvec(out[0],out[1]).push_back(q[j]);
	  }else if(q[j] < minvec(out[0], out[1]).back()){
		cout << "NO" << endl;
		isok = false;
		break;
	  }else{
		minvec(out[0], out[1]).push_back(q[j]);
	  }
	}
	if(isok) cout << "YES" << endl;
	isok = true;
	out[0].clear();
	out[1].clear();
	q.clear();
  }
  return 0;
}