#include <iostream>
#include <stack>
#include <queue>
using namespace std;

bool able;
void rec(queue<int> A,stack<int> B,stack<int> C){
	if( A.empty() ){
		able = true;
		return;
	}
	
	int tp = A.front();
	
	A.pop();
	
	if(tp > B.top() ){
	 	B.push(tp);
	 	rec(A,B,C);
	}
	if(tp > C.top() ){
	 	C.push(tp);
	 	rec(A,B,C);
	}
	
	return ;
}
int main(){
	int n,t;
	stack<int>a,b;
	a.push(0);
	b.push(0);
	cin >> n;
	while(n--){
		queue<int>input;
			able = false;
		for(int i=0;i<10;i++){
			cin >> t;
			input.push(t);
		}
		rec(input,a,b);
		cout << (able?"YES":"NO") << endl;
	}
}