#include<iostream>
using namespace std;
int ball[10];
int B=0,C=0;
int N=10;

bool solve(int i){
	if(i==N)return true;
	if(B<ball[i]){
	B=ball[i];
	if(solve(i+1))return true;
	}
	if(C<ball[i]){
	C=ball[i];
	if(solve(i+1))return true;
	}
	return false;
}



int main(){
	int X;
	cin>>X;
	for(int i=0;i<X;i++){
		for(int i=0;i<10;i++)cin>>ball[i];
		if(solve(0))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	
	
	}



return 0;
}