#include <iostream>

using namespace std;

int main( void )
{
	int n, input[10], stA[10], stB[10];
	cin >> n;
	while(n--) {
		for(int i=0; i < 10; ++i) {
			stA[i] = stB[i] = 0;
			cin >> input[i];
		}
		int idxI, idxA, idxB;
		idxI = 2; idxA = idxB = 0;
		stA[0] = input[0]; stB[0] = input[1];
		bool hit = true;
		while(10 > idxI && hit) {
			int tmp = input[idxI];
			if(stB[idxB] < stA[idxA]) { // A
				if(stA[idxA] < tmp) stA[++idxA] = tmp;
				else if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else hit = false;
			}
			else {	// B
				if(stB[idxB] < tmp) stB[++idxB] = tmp;
				else if(stA[idxA] < tmp) stB[++idxA] = tmp;
				else hit = false;
			}
			++idxI;
		}
		if(idxI == 10)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}