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

int main(){
	int N,ball,B=0,C=0;
	cin>>N;
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			cin>>ball;
			if(ball<B && ball<C){cout<<"NO"<<endl;goto x;}
			if(B<ball && C<B){B=ball;}
			else if(C<ball && B<C){C=ball;}
			else if(C<B){C=ball;}
			else 		{B=ball;}
		}	
		cout<<"YES"<<endl;
x:		B=C=0;
	}
	return 0;
}