#include<stdio.h>
#include<string.h>
#include<iostream>
#include<ctype.h>
#include<queue>
//#include<bits/stdc++.h>
#include<algorithm>
using namespace std; 
int arr[1000];  
int flash; 
int leftt,rightt;   
void dfs(int n){ 
//	printf("%d %d %d\n",n,leftt,rightt);
//	getchar();
	if(n>10){
		flash=1;
		return;
	}
	if(flash==1||flash==2) return;
	if((arr[n]<leftt)&&(arr[n]<rightt)){
		flash=2;
		return;
	}
	int a,b,c;
	a=leftt;
	b=rightt;
	c=n;
	if(arr[n]>leftt){
		leftt=arr[n];
		dfs(n+1);
		if(flash) return;
		leftt=a;
		rightt=b;
		n=c;
		if(arr[n]>rightt){
			rightt=arr[n];
			dfs(n+1);
			if(flash) return;
			flash=2;
			return;
		}else{
			flash=2;
			return;
		}
	}else if(arr[n]>rightt){
		rightt=arr[n];
		dfs(n+1);
		if(flash) return;
		flash=2;
		return;
	}else{
		flash=2;
		return;
	}
}          
                                                                                                                                                                                                                                                                                                                                             
int main(){
	int t;
	while(scanf("%d",&t)!=EOF){
	while(t--){
	flash=0;
	for(int i=1;i<=10;i++){
	   scanf("%d",&arr[i]);
	}
	leftt=-1;
	rightt=-1;
	dfs(1);
	if(flash==1) printf("YES\n");
	 else printf("NO\n");
	}	
	}
	
    return 0;
}



