#include<iostream>
#include<vector>
using namespace std;

vector<int> l, r, balls;
int lp, rp;

bool search(int n){
	bool isl = false, isr = false;
	if( n==10 ) return true;
	if( balls[n] > l[lp] ){
		l[++lp] = balls[n];
		isl = search(n+1);
		lp--;
	}
	if( balls[n] > r[rp] && !isl ){
		r[++rp] = balls[n];
		isr = search(n+1);
		rp--;
	}
	return isl || isr;
}

int main(){
	int n;
	cin >> n;
	l.resize(10); r.resize(10);
	balls.resize(10);
	for( int i=0; i<n; i++ ){
		lp = rp = 0;
		for( int j=0; j<10; j++ ){
			int b;
			cin >> b;
			balls[j] = b;
		}
		cout << (search(0)?"YES":"NO") << endl;
	}
	return 0;
}