#include<iostream>
#include<cstring>
using namespace std;

bool flag;
int a[11], b[11], c[11];
int pa, pb, pc;

void dfs(int x){
	if (pc == 11 ){
		flag = true;
		return ;
	}
	if (flag == true)
		return ;
	
	if (a[pa] < x){
		a[++pa] = x;
		dfs(c[++pc]);
		pa--;
		pc--;
	}
	if (b[pb] < x){
		b[++pb] = x;
		dfs(c[++pc]);
		pb--;
		pc--;
	}
}
		
	
	
	
void solve(){
	flag = false;
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));	
	pa = pb = pc = 1;
	
	dfs(c[pc]);
	if (flag){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}
	

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= 10; j++){
			cin >> c[j];
		}	

		solve();
	}
	
	return 0;
}
	





