#include<iostream>
int box[10];
int ltop=-1,rtop=-1;
bool ball(int i){
	if(i==9)return true; 
	if(ltop==-1 || rtop==-1){
		if(ltop==-1){
			ltop=box[i];
			return ball(i+1);
		}
		else{
		    rtop=box[i];
			return ball(i+1);	
		}
	}
	else{
		if(box[i]>ltop&&box[i]>rtop){
			if(ltop>rtop){
				ltop=box[i];
			}
			else{
				rtop=box[i];
			}
			return ball(i+1);
		}
		else if(box[i]>ltop){
			ltop=box[i];
			return ball(i+1);
		}
		else if(box[i]>rtop){
			rtop=box[i];
			return ball(i+1);
		}
		else return false;
	}
}
int main(){
	int n;
	std::cin>>n;
	for(int what=0;what<n;++what){
		for(int i=0;i<10;++i){
			std::cin>>box[i];
		}
		if(ball(0))std::cout<<"YES\n";
		else std::cout<<"NO\n";
	}
}