#include<iostream>
#include<stack>

using namespace std;

bool solve(stack<int> st1, stack<int> st2, int ball[10],int index){
	if(index == 10){
		return true;
	}
	if(st1.top() < ball[index]){
		st1.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st1.pop();
		}
	}
	if(st2.top() < ball[index]){
		st2.push(ball[index]);
		if(solve(st1,st2,ball,index+1)){
			return true;
		}else{
			st2.pop();
		}
	}
	return false;
}

int main(){
	stack<int> st1,st2;
	int ball[10];
	int n;
	cin >> n;
	for(int loop=0;loop<n;loop++){
		for(int i=0;i<10;i++){
			cin >> ball[i];
		}
		st1.push(0);
		st2.push(0);
		
		if(solve(st1,st2,ball,0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}