#include<stdio.h>
#include<string.h>

int main(){
	int ball[10];
	int cell[2][5];
	int n,i,k,j=0,flag=0;
	
	scanf("%d",&n);
	
	for(k=0;k<n;k++){
	
	for(i=0;i<10;i++)scanf("%d",&ball[i]);
	for(i=0;i<10;i+=2){cell[0][j]=ball[i]; j++;}
		j=0;
	for(i=1;i<10;i+=2){cell[1][j]=ball[i]; j++;}
		j=0;
	for(i=0;i<4;i++){
		if(cell[0][i] > cell[0][i+1] || cell[1][i] > cell[1][i])flag=1;
		else flag=0;
	}
	if(flag==0)printf("YES\n");
	else printf("NO\n");
	
	}
	return 0;
}