#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
int num[10];
int left=-100000000000,right=-100000000000;
int dfs(int m){
	if(m==10)
	return 1;
	if(num[m]>=left){
		int nleft=left;
		left=num[m];
		if(dfs(m+1))
		return 1;
		left=nleft;
	}
	if(num[m]>=right){
		int nright=right;
		right=num[m];
		if(dfs(m+1))
		return 1;
		right=nright;
	}
	return 0;
}
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		for(int i=0;i<10;i++){
			scanf("%d",&num[i]);
		}
		if(dfs(0))
		printf("YES\n");
		else
		printf("NO\n");
	}
	return 0;
} 
