#include <iostream>

using namespace std;

int main() {

	int s=0, i, N, x[10], c=0, d=0, end1=0, end2=0;
	int a[10], b[10];

	cin >> N;
	while(N!=0) {
		for(i=0; i<10; i++)
			cin >> x[i];
		i=0;
		while(i<10) {
			if(s==0) {
				if(c==0) {
					a[c]=x[i];
					c++;
					end2=0;
				}
				if(a[c-1]>x[i]) {
					s++;
					end1=1;
				}
				else {
					a[c]=x[i];
					c++;
					end2=0;
				}
			}
			if(s==1) {
				if(d==0) {
					b[d]=x[i];
					d++;
					end1=0;
				}
				if(b[d-1]>x[i]) {
					s--;
					end2=1;
				}
				else {
					b[d]=x[i];
					d++;
					end2=0;
				}
			}
			if(end1==1&&end2==1) {
				cout << "NO" << endl;
				break;
			}
			i++;
		}
		if(end1==0||end2==0)
			cout << "YES" << endl;
		N--;
	}

	return 0;

}