//AOJ 0033 Ball
#include<stdio.h>

int main(){
	int l,r,tmp;
	int n;
	scanf("%d",&n);
	while(n--){
		l = r = 0;
		bool flag = true;
		for(int i = 0;i<10;++i){
			scanf("%d",&tmp);
			if(!flag)continue;
			if(tmp<l&&tmp<r){
				flag = false;
				continue;
			}
			if(l>r){
				if(l<tmp)l=tmp;
				else r = tmp;
			}
			else{
				if(r<tmp)r=tmp;
				else l = tmp;
			}
		}
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
} 
