#include<stdio.h>
#include<malloc.h>

bool decide(int *b){
	int first = 10000;
	int i;
	for( i = 0; i < 9; i++){
		if(b[i+1] < b[i])first = b[i+1];
		break;
	}
	for(i = i+1; i < 9; i++)
		if(b[i+1] < first)return false;

	return true;
}

int main(){
	int N;
	scanf("%d",&N);
	int (*a)[10];
	a = (int (*)[10])malloc(N*10*sizeof(int));
	for(int i = 0; i < N; i++)
		for(int j = 0; j < 10; j++)
			scanf("%d",&a[i][j]);

	for(int k = 0; k < N; k++){
		int *b = a[k];
		if(decide(b) == false)printf("NO\n");
		else printf("YES\n");
		}

	return 0;
}