#include <iostream>
#include <string>
#include <vector>

std::string answer;
std::vector<int> input;

void dfs(int i, std::vector<int> L, std::vector<int> R){
	int L_flag, R_flag;
	std::vector<int> Add_L, Add_R;

	if(answer.compare("YES")==0 || i > 9) return;

	std::copy(L.begin(), L.end(), std::back_inserter(Add_L));
	std::copy(R.begin(), R.end(), std::back_inserter(Add_R));

	Add_L.insert(Add_L.end(), input[i]);
	Add_R.insert(Add_R.end(), input[i]);
	i++;

	L_flag = R_flag = 0;

	if(Add_L.size()>1){
		for(unsigned int j=0; j<Add_L.size()-1; j++){
			if(Add_L[j]>Add_L[j+1]){
				L_flag = 1;
				break;
			}
		}
	}
	if(Add_R.size()>1){
		for(unsigned int j=0; j<Add_R.size()-1; j++){
			if(Add_R[j]>Add_R[j+1]){
				R_flag = 1;
				break;
			}
		}
	}
	
	if(L_flag>0 && R_flag>0) { return; }
	if(L_flag==0) {
		if(i==10){
			answer = "YES";
			return;
		}
		else{
			dfs(i, Add_L, R);
		}
	}
	else if(R_flag==0){
		if(i==10){
			answer = "YES";
			return;
		}
		else{
			dfs(i, L, Add_R);
		}
	}
}

int main(void){
	int n, number;
	std::cin >> n;

	for(int i=0;i<n;i++){
		input.clear();
		
		for(int j=0;j<10;j++){
			std::cin >> number;
			input.insert(input.end(), number);
		}
		std::vector<int> left, right;

		answer = "CHECK";
		
		dfs(0, left, right);
		if(answer.compare("CHECK")==0) answer="NO";
		std::cout << answer << std::endl;
	}
	return 0;
}

