#include<cstdio>

using namespace std;

int boal[11];
bool ans;


void BFS(int L,int R,int c){
	
	if(c == 10 || ans){
		ans = true;
		return;
	}
	
	if(L < boal[c]){
		L = boal[c];
		BFS(L,R,c+1);
	}
	if(R < boal[c]){
		R = boal[c];
		BFS(L,R,c+1);
	}
}

int main(void){
	int n;
	while(scanf("%d", &n) != EOF){
		for(int j = 0; j < n; j++){
			ans = false;
			for(int i = 0; i < 10; i++){
				scanf("%d", &boal[i]);
			}
			
			BFS(0,0,0);
			
			printf("%s\n",ans?"YES":"NO");
		}
	}
	return 0;
}