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

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ){
		deque<int>b,c;
		bool endflag = false;
		int dummy;
		cin >> dummy;
		b.push_back( dummy );
		cin >> dummy;
		c.push_back( dummy );
		for ( int j = 0; j < 8; j++ ){
			cin >> dummy;
			if ( !endflag ) {
				if ( dummy > b[b.size()-1] )	b.push_back( dummy );
				else if ( dummy > c[c.size()-1] )	c.push_back( dummy );
				else {
					cout << "NO" << endl;
					endflag = true;
				}
			}
		}
		if( !endflag )	cout << "YES" << endl;
	}
	
	return 0;
}