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

std::string answer;
std::vector<int> input, left, right;

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

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

	L_flag = R_flag = 0;
	if(L.size()>0){
		temp = L[0];
		for(unsigned int j=1; j<L.size(); j++){
			if(temp>L[j]){
				L_flag = 1;
				break;
			}
			temp = L[j];
		}
	}
	if(R.size()>0){
		temp = R[0];
		for(unsigned int j=1; j<R.size(); j++){
			if(temp>R[j]){
				R_flag = 1;
				break;
			}
			temp = R[j];
		}
	}

	if(L_flag>0 || R_flag>0) { return; }
	else if(L_flag==0 && R_flag==0 && i==9) { answer = "YES"; }
	
	Add_L = L;
	Add_L.insert(Add_L.end(), input[i]);
	Add_R = R;
	Add_R.insert(Add_R.end(), input[i]);

	dfs(i+1, Add_L, R);
	dfs(i+1, L, Add_R);
}

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

	for(int i=0;i<n;i++){
		input.clear();
		left.clear();
		right.clear();
		
		for(int j=0;j<10;j++){
			std::cin >> number;
			input.insert(input.end(), number);
		}
		answer = "CHECK";
		dfs(0, left, right);
		if(answer.compare("CHECK")==0) answer="NO";
		std::cout << answer << std::endl;
	}
	return 0;
}

