#include<iostream>
#include<string>
using namespace std;
bool a[15]; 
int d[15];
string b,c;
int judge=0; 
void dfs(int n){
	if(n==10){
		for(int i=0;i<10;i++){
			if(a[i]==false){//进c 
				c.push_back('0'+d[i]);
			}
			else{
				b.push_back('0'+d[i]);
			}
		}
		int ok=1;
		for(int j=0;j<b.size()-1;j++){
			if(b[j]>b[j+1]){
				ok=0;
				break;
			}
		}
		for(int j=0;j<c.size()-1;j++){
			if(c[j]>c[j+1]){
				ok=0;
				break;
			}
		}
		if(ok)judge=1;
		b.clear();c.clear();
		return;
	}
	else{
		a[n]=true;
		dfs(n+1);
		a[n]=false;
		dfs(n+1);
		return;
	}
}
/*void ddfs(int n){
	cout<<n<<endl;
	if(n==10){
		judge=0;
		dfs(0);
		for(int i=0;i<n;i++){
			cout<<d[i]<<' ';
		}
		cout<<endl;
		if(judge){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
		return;
	}
	for(int i=1;i<=10;i++){
		int ok=1;
		for(int j=0;j<n;j++){
			if(d[j]==i){
				ok=0;break;
			}
		}
		if(ok){
			d[n]=i;
			ddfs(n+1);
		}
	}
}*/
int main(){
	int n;
	cin>>n;
	while(n--){
		b.clear();c.clear(); 
		judge=0;
		for(int i=0;i<10;i++){
			cin>>d[i];
		}
		dfs(0);
		if(judge){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}
