#include<iostream>
using namespace std;

#define MAX 10	// ÊÌ

int main()
{
	int A, B, C;
	int n;
	int i, j;
	int flag;

	cin>>n;
	for (i = 0; i < n; i++) {
		B = C = 0;
		flag = 1;
		for (j = 0; j < MAX; j++) {
			cin>>A;

			if (B < A) {
				B = A;
			} else if (C < A) {
				C = A;
			} else {
				flag = 0;
				break;
			}
		}
		if (flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}