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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

bool dfs(const std::vector<int> &balls, std::vector<int> l, std::vector<int> r, int i){
	if(i == balls.size()){
		return true;
	}
	if(!l.empty() && l.back() > balls[i] && !r.empty() && r.back() > balls[i]){
		return false;
	}
	bool is_success = false;

	if(l.empty() || l.back() < balls[i]){
		l.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ 
		return true;
	}
	else if(r.empty() || r.back() < balls[i]){
		r.push_back(balls[i]);
		is_success = dfs(balls, l, r, i + 1);
	}
	if(is_success){ return true; }


	return false;
}

int main(int argc, char **argv){
	int n;
	std::vector<int> balls(10);

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	for(int i = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
#if INPUT_FROM_FILE
			ifs >> balls[j];
#else
			std::cin >> balls[j];
#endif
		}

		std::vector<int> l, r;
		if(dfs(balls, l, r, 0)){
			std::cout << "YES" << std::endl;
		}
		else{
			std::cout << "NO" << std::endl;
		}
	}
	return 0;
}
