#include <iostream>
using namespace std;

int main(){
	int n;

	cin >> n;

	int* a = new int[ n * 10 ];

	for ( int i = 0; i < n; ++i ){
		cin >> a[ i*10 + 0 ] >> a[ i*10 + 1 ] >> a[ i*10 + 2 ] >> a[ i*10 + 3 ] >> a[ i*10 + 4 ]
			>> a[ i*10 + 5 ] >> a[ i*10 + 6 ] >> a[ i*10 + 7 ] >> a[ i*10 + 8 ] >> a[ i*10 + 9 ];
	}

	for ( int i = 0; i < n; ++i ){
		int right = 0, left = 0;
		for ( int j = 0; j < 10; ++j ){
			int pick = a[ i*10 + j ];
			if ( pick < right && pick < left ){
				cout << "NO" << endl;
				break;
			}else if ( pick > right && pick < left ){
				right = pick;
			}else if ( pick < right && pick > left ){
				left = pick;
			}else if ( right > left ){
				right = pick;
			}else{
				left = pick;
			}
			if ( j == 9 ){
				cout << "YES" << endl;
			}
		}
	}

	delete[] a;

	return 0;
}