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

#define MAX 10	// ÊÌ

int main()
{
	stack<int> B, C;
	int A;
	int n;
	int i;
	int flag;

	cin>>n;
	for (i = 0; i < n; i++) {
		while(B.size()) B.pop();
		while(C.size()) C.pop();
		flag = 1;
		while (B.size()+C.size() < MAX) {
			cin>>A;

			if (B.size()==0) {
				B.push(A);
				continue;
			}
			else if (C.size()==0) {
				C.push(A);
				continue;
			}

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

	return 0;
}